Reverse the digits
Read a positive whole number and print its digits in reverse order. Leading zeros in the result disappear, so 120 becomes 21.
Input
1234
Expected output
4321
Input
120
Expected output
21
Show a hint
n % 10 is the last digit and n / 10 removes it. Build the result with rev = rev * 10 + digit.
Show a solution
Loading the editor…
Run the tests to check your solution.