Reverse of a Given Number

Problem: Program to find reverse of a given number.

To reverse the given number do the following steps:

  1. Multiply reverse with 10 and add the remainder of a number N by modulo-division with 10.
  2. Remove last digit of a number N by dividing it with 10.
  3. 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;
}
Sample Input
256
Sample Output
652