Program to check given string is Palindrome or not in C++
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cout<<"Enter a string"<<endl; //Requesting String
cin>>s;
string t=s; //Storing original string
reverse(s.begin(), s.end()); //Reversing the original string
if(s==t){
cout<<"Palindrome String"<<endl; //If equal print palindrome
}
else{
cout<<"Not a Palindrome String"<<endl; //If not equal print not a palindrome
}
return 0;
}
Output
Enter a string
Dragon
Not a Palindrome String
0 Comments