/* Write an Interactive C Program to Check Whether a Given String is Palindrome or Not, Using Pointer*/
main()
{
char ch[20],a[20],*p;
int i,len,c=0;
clrscr();
printf("Enter a string \(Word\).");
gets(ch);
len=strlen(ch);
p=a;
for(i=len-1;i>=0;i--)
{
*p=ch[i];
p++;
}
for(i=0;i<len;i++)
{
if(ch[i]==a[i])
c++;
}
if(c==len)
printf("%s is a palindrome string.",ch);
else
printf("%s is not a palindrom string.",ch);
getch();
}
Output:
main()
{
char ch[20],a[20],*p;
int i,len,c=0;
clrscr();
printf("Enter a string \(Word\).");
gets(ch);
len=strlen(ch);
p=a;
for(i=len-1;i>=0;i--)
{
*p=ch[i];
p++;
}
for(i=0;i<len;i++)
{
if(ch[i]==a[i])
c++;
}
if(c==len)
printf("%s is a palindrome string.",ch);
else
printf("%s is not a palindrom string.",ch);
getch();
}
Output:
No comments:
Post a Comment