Palindrome is a word , number that can be read same front direction and opposite direction.
Example :
Example :
- Palindrome words (Strings )
- Racecar
- Madam
- Level
- Radar
- Toot
- Pop
- Palindrome numbers
- 121
- 1221
- 141
- 1234321
- 676
1.To Check whether Given String Is Palindrome or Not :
Program :
Note : Madam ,First letter M is a Capital and Last letter m is a small letter . There ASCII value is deference M = 77 and m= 109 . Toupper function works that small m letter convert to capital M letter 109-32=77.
Output :
2.To Check whether Given Number Is Palindrome or Not :
Program :
Output :
Program :
#include<stdio.h>
#include<conio.h>
int pali( char []);
void main()
{
char ch;
do{
int n;
char s[20];
clrscr();
printf("\n Enter the string:");
gets(s);
n=pali(s);
if(n==1)
printf("\n <%s> is palindrome \n",s);
else
printf("\n <%s> not palindrome \n",s);
printf("Continue(y/n):");
ch=getch();
}while(ch=='y'||ch=='Y');
}
int pali(char s[])
{
int r,n=1,l=0;
char toupper(char);
for(r=0;s[r]!='\0';r++);
r=r-1;
while(l<r)
{
if(toupper (s[l])!=toupper(s[r]))
{
n=0;
break;
}
l++;
r--;
}
return n;
}
char toupper(char c)
{
if(c>='a' && c<='z')
c=c-32;
return c;
}
Note : Madam ,First letter M is a Capital and Last letter m is a small letter . There ASCII value is deference M = 77 and m= 109 . Toupper function works that small m letter convert to capital M letter 109-32=77.
Output :
2.To Check whether Given Number Is Palindrome or Not :
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c=0,r=0;
clrscr();
printf("\t Enter any no :");
scanf("%d",&a);
b=a;
while(a>0)
{
r=a%10;
c=c*10+r;
a=a/10;
}
if(c==b)
printf("\t <%d> the no is palindrome",b);
else
printf("\t <%d> is not palindrome",b);
getch();
}
Output :