C program to find whether a string is a palindrome or not

Complete C program to find whether a string is a palindrome or not

#include <stdio.h>
#include <conio.h>
int main()
{
char str[100];
int i = 0, j, length = 0;
clrscr();
printf("\n Enter the string : ");
gets(str);
while(str[i] != '\0')
{
 length++ ;
 i++ ;
}
i=0;
j = length ā€“ 1;
while(i <= length/2)
{

if(str[i] == str[j])
 {
 i++;
jā€“ā€“;
}
 else
 break;
}
if(i>=j)
printf("\n PALINDROME");
else
printf("\n NOT A PALINDROME");
return 0;
}

Output

Enter the string: madam
PALINDROME

Leave a Comment