c program to reverse a number with explanation

In this example, I shared c program to reverse a number with explanation using while loop. Learn about C loop control.

Also learn Palindrome of a number in c

C Reverse Number 


For example, if the user enters 411 then the output will:

The reverse of 411 is 114



#include<stdio.h>
int main()
{
 int orig,save,r,rev=0;
  printf("\n Enter the number:");
  scanf("%d",&orig);.
   save=orig;
    while(orig!=0)
   {
    r=orig%10;
    rev=rev*10+r;
    orig=orig/10;
   }
   printf("The reverse of %d is %d",save,rev);
 return 0;
}

NOTE: You have any problem in above c program do not hesitate and write your problem in the comment box. I will support your problem.

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form