CJCoding With Joseph
15free / daySign inCreate account

Digits Reversed With An Accumulator

Write reverse_digits(n: int, acc: int) -> int that returns the digits of a non-negative integer n in reverse order as a number, using the second parameter as an accumulator that carries the answer built so far: when n is 0 return acc; otherwise recurse with n with its last digit removed (n // 10) and acc moved up one place (times 10) plus that last digit (n % 10). Trailing zeros disappear, so 1200 reverses to 21. Do NOT write a main block or any top-level test code; the tests construct the calls with an accumulator of 0. Input: one integer n, no prompt, which the tests read and pass to your function before printing the value it returns.

Expected Output:

4321

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
RecursionOperators
📥 Auto-Input:
1234\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.