Remainder Without Modulo
EasyP3Coding
Return the remainder of a divided by b without using the % operator or division. Use recursion.
Both numbers are non-negative and b is at least 1.
Example 1
- Input
- a = 10, b = 3
- Output
- 1
- Why
- 10 = 3 * 3 + 1.
Example 2
- Input
- a = 9, b = 3
- Output
- 0
Example 3
- Input
- a = 0, b = 7
- Output
- 0
Constraints
- 0 <= a <= 500
- 1 <= b <= 500
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 9. ⌘Enter runs, ⌘⇧Enter submits.