How To Check Word or String is Palindrome or not ?

We can check given word is palindrome or not through below code:-

 

#include<stdio.h>
#include<string.h>
main( )
{
char str[10];
int i=0,j,flag;
printf (“Enter the word “) ; //Kanak
scanf(“%s”,str) ;
j=strlen(str)-1;
while (i<=j )
{
if(str[i]==str[j])
flag=1;
else
flag=0;
break;
i++;
j–;
}
if (flag==1)
printf (“Word is palindrome\n” );
else
printf (“Word is not palindrome\n” );
}

 

output:-

Leave a Reply

Your email address will not be published. Required fields are marked *