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

Run it Now
#include<stdio.h>
#include<string.h>

int main() {

    char str[100];
    int len, f = 1, i = 0;

    printf("Enter a String :");
    fgets(str, 100, stdin);

    len = strlen(str);
    len = len - 1;

    while (str[i] != '\0') {
        if (str[i] != str[len]) {
            f = 0;
            break;
        }
        len--;
        i++;
    }

    if (f == 1) {
        printf("\nString is Palindrome :%s", str);
    } else {
        printf("\nString is Not Palindrome :%s", str);
    }

    return 0;
}

Output:

Enter a String :level
String is Palindrome :level