Q:

C Program to reverse number

belongs to collection: C Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<stdio.h>  
 int main()    
{    
int n, reverse=0, rem;    
printf("Enter a number: ");    
  scanf("%d", &n);    
  while(n!=0)    
  {    
     rem=n%10;    
     reverse=reverse*10+rem;    
     n/=10;    
  }    
  printf("Reversed Number: %d",reverse);    
return 0;  
}   

Output:

Enter a number: 123
Reversed Number: 321

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Program to swap two numbers without third variab... >>
<< Sum of digits program in C...