The word palindrome means that when read from left to right or right to left it is the same. The spelling of palindromic words is the same on either side. In C++ Programs we can write a program to check if the string is palindrome or not.
C++ Program to check if a string is a palindrome or not
#include <iostream>
#include <stdlib.h>
int main ()
{
system ("cls");
char string[80],c ;
std::cout<<"Enter a string (maximum 79 characters only) \n";
std::cin.getline(string,80);
for (int len = 0 ; string[len] != '\0'; ++len) ;
int i,j,len, flag = 1 ;
for (i = 0, j = len - 1 ; i < len / 2 ; ++i, --j)
{
if (string[i]=string[j])
{
flag = 0 ;
break ;
}
}
if (flag)
std::cout <<"It is a palindrome \n";
else
std::cout<<"It is not a palindrome \n" ;
return 0 ;
}
The output of the C++ Code