Thursday 2 December 2010

write a function for palindrome or not?

/*palindrome or not?
Defn:
A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed. Like 16461, for example, it is "symmetrical".
*/

#include<stdio.h>
#include<conio.h>
int palin(int n)
{
 int rem,sum=0;
 while(n!=0)
 {
  rem=n%10;
  sum=sum*10+rem;
  n=n/10;
 }
 return(sum);
}
void main()
{
 int n,rev;
 clrscr();
 printf("etner any number\n");
 scanf("%d",&n);
 rev=palin(n);
 if(rev==n)
 {
  printf("Palindrome number\n");
 }
 else
 {
  printf("not a Palindrome number\n");
 }
getch();
}


No comments:

Post a Comment