C++ Program to Check Whether a String is Palindrome or not

In this program, you'll learn to check a given string is Palindrome or not.

A string is called Palindrome, if the original string and reverse string of original string are same.

To check if a string is palindrome or not follow below steps:

1) Declare two string: f and r.

2) Find Reverse of string.

3) Check if the reversed string is equal to the given string.

Source Code
using namespace std;

int main()
    int f, r, len=0;
    char str[20];
    cout<<"Enter the string: ";

    // First calculate the length of string
    while(str[len] != '\0')

    f = 0;
    r = len-1;

    while(f <= r)
        if(str[f++] != str[r--])
            cout<<"String is not Palindrome";
            return 0;
    cout<<"String is Palindrome";
    return 0;
Enter the string: nitin
String is Palindrome

Enter the string: ramesh
String is not Palindrome

"Coding Hub - Learn to code" app now available on Google Play Store