program to check if a string is panildrome in c++

what is a panildromic string ?

A string which when read from right is same as when read from left .


Program to check if a string is panildrome or not ?



 #include<bits/stdc++.h>

using namespace std;

bool is_panildrome(string &s)

{ int len = s.length(); 

int k = len -1;

int flag = 0;

    for(int i = 0 ; i < len/2 ; i++ )

    {   

        if(s[i] == s[k])

        {

             k-- ; 

             continue;

             

        }

        else

        {   flag = 1;

            break ;

        }

         

    }

    if(flag == 1)

     return false ;

     

    return true;

}

int main()

{  

   string  s = "abiiba";

   bool x = is_panildrome(s);

   cout << x ;

    

}

Comments