160. C Program to Check Given String is Palindrome or Not.
How does this program work?
- This Program is used to check the given string is palindrome or not.
Here is the code
#include <string.h>
int main()
{
// Check the given string palindrome or not
char string1[20];
int i, length;
int flag = 0;
printf("Enter a string:\n");
scanf("%s", string1);
length = strlen(string1);
for(i=0;i < length ;i++)
{
if(string1[i] != string1[length-i-1])
{
flag = 1;
break;
}
}
if (flag)
{
printf("%s is not a palindrome", string1);
}
else
{
printf("%s is a palindrome", string1);
}
return 0;
}