C Program to Reverse a Number
Posted by Samath
Last Updated: January 02, 2017

Write a C program that reverse the number entered by the user and then prints the reversed number. For example if the user enter 123 as input then 321 is printed as output. 

Code:

#include<stdio.h>
 
int main() {
   int num, rem, result = 0;
 
   printf("\nEnter Number: ");
   scanf("%d", &num);
 
   while (num >= 1) {
      rem = num % 10;
      result = result * 10 + rem;
      num = num / 10;
   }
 
   printf("\nResult: %d", result);
   return (0);
}