Check string Palindrome code example
Example 1: check if a string is palindrome cpp
// Check whether the string is a palindrome or not.
#include
using namespace std;
int main(){
string s;
cin >> s;
int l = 0;
int h = s.length()-1;
while(h > l){
if(s[l++] != s[h--]){
cout << "Not a palindrome" << endl;
return 0;
}
}
cout << "Is a palindrome" << endl;
return 0;
}
Example 2: check palindrome
bool isPlaindrome(string s)
{
int i=0;
int j=s.length()-1;
while(ij) return 1;
else return 0;
}