Monday 24 July 2017

Program to check if a string is palindrome or not.

PROGRAM
Program to check if a string is palindrome or not.

     #include<iostream.h>
     #include<conio.h>
     #include<stdlib.h>
        int main()

          {     system ("cls");
                char string[80],c;
                cout<<"Enter a string (max.79 characters)\n";
                cin.getline(string,80);
                for(int len=0;string[len]!='\0';++len);
            int i,j,flag=1;
              for(i=0,j=len-1;i<len/2;++i,--j)
             {     if(string[i]!=string[j])
                 {  flag=0;
                break;
                 }
              }
        if(flag)
             cout<<"It is a palindrome \n";
         else
            cout<<"It is not a palindrom \n";
               getch();
               return 0;
            }
========================================================================
OUTPUT

 Enter a string (max.79 characters) : nitin
   
 It is a palindrome

========================================================================

No comments:

Post a Comment