C++ program to check whether a given string is a palindrome
kw.cpp
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cout<<"———————————————————————————————————————————";
    cout<<"\nProgram to check string is palindrome | not";
    cout<<"\n———————————————————————————————————————————";
    string s1, s2;
    cout<<"\nEnter the string ";
    getline(cin, s1);
    s2 = s1;
    reverse(s1.begin(), s1.end());
    if (s1 == s2)
    {
        cout<<"\n"
            <<s2<<" is a palindrome";
    }
    else
    {
        cout<<"\n"
            <<s2<<" is not a palindrome";
    }
    cout<<"\n———————————————————————————————————————————\n";
}
Output
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program to check string is palindrome | not ——————————————————————————————————————————— Enter the string WAR WAR is not a palindrome ——————————————————————————————————————————— kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program to check string is palindrome | not ——————————————————————————————————————————— Enter the string RAR RAR is a palindrome ——————————————————————————————————————————— kodingwindow@kw:~$
Advertisement