Dremendo Tag Line

Input word and check palindrome word or not in C

String Methods - Question 3

In this question, we will see how to input a word and check if it is a palindrome word or not in C programming. To know more about string methods click on the string methods lesson.

Q3) Write a program in C to input a word and check if it is a palindrome word or not.

Program

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>

int main()
{
    char s[50];
    int i,c=0,l;

    printf("Enter a word\n");
    gets(s);
    l=strlen(s);

    for(i=0; i<l; i++)
    {
        if(tolower(s[i])==tolower(s[l-i-1]))
        {
            c++;
        }
    }

    if(c==l)
    {
        printf("Palindrome word");
    }
    else
    {
        printf("Not palindrome word");
    }
    return 0;
}

Output

Enter a word
Madam
Palindrome word
video-poster