Home >>c programs >C Program to reverse number

C Program to reverse number

C Program to reverse number

C program to reverse a number defined a number written by the user, and then prints the reversed number on the screen. A number in C is reverse by using loop and arithmetic operators. It can revert an original number in its opposite direction from right to left.

For example:- if you can enter 7645 as input then 5467 is printed as output.

Let's take an example oc C program to reverse number:

#include<stdio.h>  
 int main()    
{    
int num, rev=0, rem;    
printf("Enter Your  number = ");    
  scanf("%d", &num);    
  while(num!=0)    
  {    
     rem=num%10;    
     rev=rev*10+rem;    
     num=num/10;    
  }    
  printf("Number after reversed = %d",rev);    
return 0;  
}   
Output :
Enter Your number = 123
Number after reversed = 321
Output :
Enter Your number = 12345
Number after reversed = 54321

Popular Tutorials