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.
reverse_digits(1234)→4321reverse_digits(1200)→21reverse_digits(7)→7int reverse_digits(int n)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;
}
Run tries the examples. When they look right, Submit.