C Program to reverse number


We can reverse a number in c using loop and arithmetic operators. In this program, we are getting number as input from the user and reversing that number. Let's see a simple c example to reverse a given number.

  1. #include<stdio.h>  
  2.  int main()    
  3. {    
  4. int n, reverse=0, rem;    
  5. printf("Enter a number: ");    
  6.   scanf("%d", &n);    
  7.   while(n!=0)    
  8.   {    
  9.      rem=n%10;    
  10.      reverse=reverse*10+rem;    
  11.      n/=10;    
  12.   }    
  13.   printf("Reversed Number: %d",reverse);    
  14. return 0;  
  15. }   

Output:

Enter a number: 123
Reversed Number: 321
Previous Post Next Post