C Program to check string is palindrome or not
In this program, You will learn how to check string is palindrome or not in c.
Some palindrome string example: madam, mam, dad
Example: How to check string is palindrome or not in c.
#include<stdio.h>
#include<string.h>
int main() {
char str[100];
int len, f = 1, i = 0;
printf("Enter a string:");
scanf("%[^\n]%*c", str);
len = strlen(str);
len = len - 1;
while (str[i] != '\0') {
if (str[i] != str[len]) {
f = 0;
break;
}
len--;
i++;
}
if (f == 1) {
printf("String is palindrome:%s", str);
} else {
printf("String is not palindrome:%s", str);
}
return 0;
}
Output:
Enter a string:level
String is palindrome:level