The Division via Subtraction

EasyAcc. 96.4%
+15 XP 5

Deconstruction

Division is just repeated subtraction. $10 div 3 = (10 - 3 - 3 - 3)$, leaving a remainder of 1 and a quotient of 3.

The Assignment

Your function receives parameters dividend and divisor.

  1. Initialize quotient to 0.
  2. Use a while loop as long as dividend is greater than or equal to divisor.
  3. In each step:
    • Subtract divisor from dividend.
    • Increment quotient.
  4. After the loop, print: "Quotient: Q, Remainder: R"

01EXAMPLE 1

Inputdividend=10, divisor=3
OutputQuotient: 3, Remainder: 1

Explanation: Subtracts 3 three times.

Constraints

  • Strictly avoid the / and % operators.
  • Use a while loop.
MathLoops
JavaScript
Loading...
3 Hidden

Input Arguments

dividend10
divisor5

Expected Output

Quotient: 2, Remainder: 0

Click RUN to test your solution