Check the given string is palindrome or not in C++ | C++ program to check palindrome string

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

Post a Comment

0 Comments