Program to find reverse of a number in C

Logic:

  • Enter the number n example n=345
  • Reverse=543

Algorithm

  1. Enter the number as n
  2. Initially assign rev=0
  3. while(n>0)
  4. {
  5. r=n%10;
  6. rev = rev * 10 + r;
  7. n=n/10;
  8. }
  9. Print rev

Program

#include<stdio.h>
int main()
{
    printf("***************************************************************");
    printf("\n***************************************************************");
    printf("\n**         WAP to find reverse of a number                    *");
    printf("\n**              Created by Sheetal Garg                      **");
    printf("\n**                Assistant Professor                        **");
    printf("\n**                Phone No:9467863365                        **");
    printf("\n***************************************************************");
    printf("\n***************************************************************\n");
    int i,n,r,rev=0;
    printf("Enter the no n \n");
    scanf("%d",&n);
   while(n>0)
   {
       r=n%10;
       n=n/10;
       rev=rev*10+r;
   }
   printf("reverse is %d",rev);
}

Output 1

***************************************************************************
***************************************************************************
**                     WAP to find reverse of a number                    *
**                          Created by Sheetal Garg                      **
**                            Assistant Professor                        **
**                            Phone No:9467863365                        **
***************************************************************************
***************************************************************************
Enter the no n
456
reverse is 654
error: You can only copy the programs code and output from this website. You are not allowed to copy anything else.