Sunday, 19 August 2012

string is a palindrome or not



#include<iostream>
using namespace std;
#include<conio.h>
int main()
{
   char s1[20];
   int i, j, len=0, flag=0;
   cout<<"\nEnter any string: ";
   gets(s1);
   for (i=0; s1[i]!='\0'; i++)
        len++;
   i = 0;
   j = len-1;
   while (i < len)
 {
        if (s1[i] != s1[j])
        {
              flag = 1;
              break;
        }
        i++;
        j--;
   }
   if (flag == 0)
        cout<<"\nString is palindrome";
   else
        cout<<"\nString is not palindrome";
   getch();
}

No comments:

Post a Comment