How To Reverse A Number in C

Introduction 
  • In this article, I'm going to explain how to reverse a number in C language.
Software Requirements 
  • Turbo C++ OR C 
Programming 
  1. #include<stdio.h>  
  2. int main()  
  3. {  
  4. int n, reverse = 0;      
  5. printf("Enter a number to reverse\n");      
  6. scanf("%d",&n);  
  7. while (n != 0)  
  8. reverse = reverse * 10;  
  9. reverse = reverse + n%10;  
  10. n = n/10;  
  11. }  
  12. printf("Reverse of entered number is = %d\n", reverse);      
  13. return 0;  
  14. }  
Explanation
  • To reverse a number in C, we can use the following code where the number is entered by the user, and then it is reversed on the output screen.

     programming
Output

Output
Ebook Download
View all
Learn
View all