View All C Programs

 Previews Example  View All C Programs Next Example 

Program to Reverse a Number in C

This program takes an integer number from user and reverses that number.
#include <stdio.h>
#include <conio.h>
 main()
{
  int n, reverse=0, rem;
  printf("Enter an integer: ");
  scanf("%d", &n);
  while(n!=0)
  {
     rem=n%10;
     reverse=reverse*10+rem;
     n/=10;
  }
  printf("Reversed Number = %d",reverse);
  getch();
}
    
Result
Enter an integer: 54321
Reversed Number = 12345