Kodewick
Start learning →
Starter←→0 / 50

Reverse a number

#019Starterr * 10 + n % 105 min

Flip the digits of a non-negative whole number. Write reverse_digits(n) to return the flipped number. 1234 becomes 4321; 1200 flipped is 0021, and leading zeros don't count, so it is 21. 0 stays 0.

Examples
reverse_digits(1234)→4321
reverse_digits(1200)→21
reverse_digits(7)→7
The functionint reverse_digits(int n)
main.c
int reverse_digits(int n) {
    int r = 0;
    while (n > 0) {
        // your code here: add the last digit of n to the end of r
        n = n / 10;
    }
    return r;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.