C program to reverse the given number

C program to reverse the given number:

Here I shared C program to reverse the given number using a while loop statement.

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

The reverse of 561 is 165



#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.

Share this

0 Comment to "C program to reverse the given number"

Post a Comment