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
Post A Comment:
0 comments: