Saturday, November 7, 2009

To Check Palindrome | C Programming

//wap to check if the no is palindrome
#include
#include
#include
void main()
{
int i,n=, r=0, s=0, c=0, rev=0, x,y; //students are advised to use
clrscr(); // “long” instead of “int” so as to use high figure no
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
x=n; y=n;
while(n!=0){ // to count the digits
n=n/10;
c=c+1;}
printf(“\n The total digits in number : %d”,c);
while(x!=0){ //decrement of the power of 10
c=c-1;
r=x%10;
x=x/10;
rev=rev + r*pow(10,c);}

printf(“\n\n\a\tThe reverse is :%d”,rev);
if(rev==y)
{printf(“\n Palindrome”);}
else
{printf(“\n Not Plaindrome”)}
getch();
}
o/p→
enter a number : 12321
The reverse is : 12321
Plindrome


No comments:

Post a Comment