Example & Tutorial understanding programming in easy ways.

Check palindrome string in C language

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
printf("Enter string");
scanf("%s",&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))
{
printf("String is not palindrome");
}
else
printf("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.




Read More →
Search
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!