data-structures · beginner · ~15 min
Reverse a number's digits recursively.
Implement:
int reverse_number(int n);
Return n (n >= 0) with its decimal digits reversed, computed recursively. E.g. 1230 -> 321.
n >= 0.
Digit-reversed value.
Trailing zeros of the input disappear (1230 -> 321).
#include <stddef.h>
/* Reverse the decimal digits of n (n>=0), computed recursively. e.g. 1230 -> 321. */
int reverse_number(int n){ (void)n; return 0; }
Trying to reverse without an accumulator argument.
0 reverses to 0.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.