Reverse a Number
Completed
Read a positive integer and print it reversed (as a number).
Input
One integer ≥ 1.
Output
The reversed number.
Example
Input
1234
Output
4321
Editor
C
Hints
Take the last digit with % 10 and append it to rev.
Solution explanation
Each step moves one digit from n to rev.
Show solution
#include <stdio.h>
int main() {
int n, rev = 0;
scanf("%d", &n);
while (n > 0) {
rev = rev * 10 + n % 10;
n /= 10;
}
printf("%d\n", rev);
return 0;
}