C++ Program to check string is palindrome or not


In this program, You will learn how to check string is palindrome or not in C++.


Some palindrome string's example: madam, mam, dad


Example: How to check string is palindrome or not in C++

Run it Now
#include<iostream>
#include<cstring>
using namespace std;

int main() {

    char str[100];
    int size, f = 1, i = 0;

    cout << "Enter a String :";
    cin.getline(str, 100);

    size = strlen(str);
    size = size - 1;

    while (str[i] != '\0') {
        if (str[i] != str[size]) {
            f = 0;
            break;
        }
        size--;
        i++;
    }

    if (f == 1) {
        cout << "\nString is Palindrome :" << str;
    } else {
        cout << "\nString is Not Palindrome :" << str;
    }

    return 0;
}

Output:

Enter a String :level
String is Palindrome :level