CodeMIRAI
0 XP

Reverse the digits

Medium +50 XP Solved

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
C
Loading the editor…
Run the tests to check your solution.