Wednesday 16 April 2014

Program to Check Whether a Given String is Palindrome or Not

/* 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:
Output of  C Program to Check whether a string is palindrome or not

No comments:

Post a Comment