C Program to Reverse a Number

C Program to Reverse a Number

#include<stdio.h>

main()
{
 int n,temp,rev=0,t;

printf("Enter a no:\n");
scanf("%d",&n);

temp=n;    //hold entered value in other variable.otherwise original value lost


while(temp>0)    //loop run until no. > 0
{

t=temp%10;      //store remainder in other variable
rev=rev*10+t;    //reverse no store
temp=temp/10;   //divide by 10 so again module take of remaining digit

}

printf("original no is:%d\n",n);

printf("Reverse no is:%d\n",rev);

if(n==rev)
{

printf("palindrome no.\n");

}
else

printf("Not a palindrome no.\n");

}

Related Posts