Monday, September 12, 2011

find whether the given string is a palindrome or not

TO find whether the given string is a palindrome or not */
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
    char string[90];
    int i,j,len,flag=0;
    clrscr();
    printf("\nEnter the string to be checked for Palindrome:\n");
    gets(string);
    len=strlen(string);   // or for(len=0;string[len]!='\0';len++);
    for(i=0,j=len-1;i<len/2;i++,j--)
      {
         if(string[i]!=string[j]) // check whether palindrome
        flag=1;
      }
    if(flag==1)
        printf("\nString is not a Palindrome");
    else
        printf("\nString is a Palindrome");
getch();
}

No comments:

Post a Comment

Popular 5 Posts Last 7 days