More you share, more you have!!!

More you share, more you have!!!

C program to check whether string is palindrome or not?

Q. How to check whether string is palindrome or not?

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.

Source Code:->

#include<stdio.h>
#include<conio.h>
void main()
{
char name[70];
int i,j,len;
clrscr();
printf("Enter string to check whether its a pallindrome or not? \t");
scanf("%s",name);
printf("\n User string is %s \t",name);
for(i=0;name[i]!='\0';i++);
len=i;
printf("\n Length of string is \t %d",len);
for(i=0,j=len-1;i<len,j>=0;i++,j--)
{
if(name[i]!=name[j])
{
printf("\n Not a pallindrome");
break;
}
else
{
printf("\nMatched characters are: %c\t,\t%c",name[i],name[j]);
if(i==j-1)
{
printf("\n\n its a pallindrome");
break;
}
}
}
getch();
}


Output 1 :Enter string to check whether its a pallindrome or not?        pavilion
User string is pavilion
Length of string is   8
Not a palindrome

Output 2:Enter string to check whether its a pallindrome or not?       oproorpo
User string is oproorpo
Length of string is   8
Matched characters are: o        ,       o
Matched characters are: p        ,       p
Matched characters are: r        ,       r
Matched characters are: o        ,       o
 its a palindrome

Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment