C Program to reverse a number

C Program to Reverse a number is a common program very widely asked in exams and practicals. C program to reverse a number is a simple program that reverses the digits of a number and then prints it. For example if we have 1234 then it would be printed as 4321 in reverse order.

In this program we will let the user to enter a number then we will reverse it and then will print the result. We will reverse the number by the help of loop and will print the reversed number.


#include <stdio.h>
 
int main()
{
   int n, reverse = 0;
 
   printf("Enter a number to reverse\n");
   scanf("%d", &n);
 
   while (n != 0)
   {
      reverse = reverse * 10;
      reverse = reverse + n%10;
      n       = n/10;
   }
 
   printf("Reverse of entered number is = %d\n", reverse);
 
   return 0;
}
Previous
Next Post »