Saturday, March 10, 2012

Write a C program to check whether a given number is palindrome or not.

#include 
#include 
void main()
{
 long int n, num, rev = 0, dig;
 printf("\n Enter a number...: ");
scanf("%ld", &num);
 n = num;
while(num>0)
{
dig = num % 10;
 rev = rev * 10 + dig;
 num = num / 10;
 }
 if (n == rev)
 printf("\nGiven number is a palindrome");
 else
 printf("\n Given number not a palindrome");
 getch();
}

No comments:

Post a Comment

Sociable