Input word and check palindrome word or not in C++
String Methods - Question 3
In this question, we will see how to input a word and check if it is a palindrome word or not in C++ programming. To know more about string methods click on the string methods lesson.
Q3) Write a program in C++ to input a word and check if it is a palindrome word or not.
Program
#include <iostream>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
using namespace std;
int main()
{
char s[50];
int i,c=0,l;
cout<<"Enter a word\n";
gets(s);
l=strlen(s);
for(i=0; i<l; i++)
{
if(tolower(s[i])==tolower(s[l-i-1]))
{
c++;
}
}
if(c==l)
{
cout<<"Palindrome word";
}
else
{
cout<<"Not palindrome word";
}
return 0;
}
Output
Enter a word Madam Palindrome word