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++.

#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 << "String is palindrome:" << str;
    } else {
        cout << "String is not palindrome:" << str;
    }

    return 0;
}

Output:

Enter a string:level
String is palindrome:level

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.