Write a C++ program to check that given string is a Palindrome or not.


Program Code:
#include<iostream>
using namespace std;
int main()
{
int i,j,length,flag=1;
char array[20];

cout<<"Enter a string to check for Palindrome : ";
cin>>array;
cout<<endl;
for(length=0;array[length]!='\0';++length);   
for(i=0,j=length-1;i<length/2;++i,--j)
{
if(array[j]!=array[i])
flag=0;
if(flag==1)
{
cout<<"Entered string is a Palindrome.";
}
else
{
cout<<"Entered string is not a Palindrome.";
}
return 0;
}


The program output is tested on www.jdoodle.com
Output:
Enter a string to check for Palindrome :  mukeshsekum
Entered string is a Palindrome.


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: