Answer:
c++ program to check palindrome.
#include <bits/stdc++.h>
using namespace std;
int main() {
string pal;
bool b=1;
getline(cin,pal);//taking input of a word or a line.
int s=0,e=pal.length()-1;
while(s<e)//loop to check palindrome.
{
if(pal[s]!=pal[e])
{
b=0;
break;
}
s++;
e--;
}
if(b)
{
cout<<"Text is palindrome"<<endl;//printing the message.
}
else
{
cout<<"Text is not palindrome"<<endl;//printing the message.
}
return 0;
}
Output:-
geeks skeeg
Text is palindrome
geeks skeegs
Text is not palindrome
Explanation:
I have taken a string pal for the input of word or a text then I have taken two pointers one for starting and one for the end.In the loop i am keep checking the first and last characters of the string if they are same then continue otherwise break out of the loop and print not palindrome.