Problem: Program to find reverse of a given number.
To reverse the given number do the following steps:
- Multiply reverse with 10 and add the remainder of a number N by modulo-division with 10.
- Remove last digit of a number N by dividing it with 10.
- Repeat steps 1 and 2 until the value of N becomes 0.
#include<stdio.h>
int main() {
int num, reverse=0;
scanf("%d",&num);
while(num!=0){
reverse = reverse * 10 + num % 10;
num /= 10;
}
printf("%d",reverse);
return 0;
}
int main() {
int num, reverse=0;
scanf("%d",&num);
while(num!=0){
reverse = reverse * 10 + num % 10;
num /= 10;
}
printf("%d",reverse);
return 0;
}
Sample Input
256
Sample Output
652
256
Sample Output
652