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