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.
- Initialize
quotientto 0. - Use a
whileloop as long asdividendis greater than or equal todivisor. - In each step:
- Subtract
divisorfromdividend. - Increment
quotient.
- Subtract
- After the loop, print: "Quotient: Q, Remainder: R"
01EXAMPLE 1
Input
dividend=10, divisor=3Output
Quotient: 3, Remainder: 1Explanation: Subtracts 3 three times.
Constraints
- Strictly avoid the / and % operators.
- Use a while loop.
MathLoops
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
dividend10
divisor5
Expected Output
Quotient: 2, Remainder: 0
Click RUN to test your solution