palindrome string in C++ by R4R Team

Palindrome string:
-Palindrome string are those strings which are equal when we traverse string in normal and reverse direction.

Example-
string is "saas"
It is palindrome string
string is "Myhome"
It is not palindrome string

program-

#include< stdio.h>
#include< string.h>
int main()
{
char s1[20],s2[20];
int i=0,len=0;
//input of string
cout<<"Enter string"< cin>>s1;
// find length
while(s1[i++]!='')
len++;
//Now reverse
i=0;
while(s1[i]!='')
{
s2[i]=s1[len-i-1];
i++;
}
if(strcmp(s1,s2))
{
cout<<"String is not palindrome";
}
else
cout<<"String is palindrome";
}


output-

Enter string
12321
String is palindrome
Enter string
Mystring
String is not palindrome

-In this program, Firstly we take an input of the string.
-Then we reverse that string and store in another variable.
-Then compare both string by using strcmp() function.
-If both are equal then it is palidrome otherwise it's not.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!