Friday, October 14, 2011

Write a C program to reverse a given four-digit number and check whether the number is a palindrome or not. Note:A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction Ex: MADAM, LEVEL, POP, RADAR etc...

#include
int main()
{
int a,b,c=0,d;
printf("\tEnter a number u want:"); //USER INPUT
scanf("%d",&a);
d=a;
while(a)
{
b=a%10;
a=a/10;
c=c*10+b;
}
printf("\tReverse number is :%d\n",c); //printing of reverse number
if(d==c)
printf("\t%d is a palindrome\n",d); //prints if polyndrome
else
printf("\t%d is not a palindrome\n",d); //prints if not polyndrome
}

No comments:

Post a Comment