Input a word and check if it is palindrome word or not using a function in C
Function - Question 4
In this question, we will see how to input a word and check if it is palindrome word or not in C programming using a function. To know more about function click on the function lesson.
Q4) Write a program in C to input a word and check if it is palindrome word or not using a function. The function should return 1 if the word is palindrome else return 0.
A word is called palindrome if its reverse form is equal the original word.
Example: madam Reverse Form: madam
Program
#include <stdio.h>
#include <conio.h>
#include <string.h>
int palindrome(char str[])
{
char rev[30];
strcpy(rev,str);
strrev(rev); // reverse the word using string reverse method
if(strcmpi(str,rev)==0)
{
return 1;
}
return 0;
}
int main()
{
char s[30];
printf("Enter a String: ");
gets(s);
if(palindrome(s)==1)
{
printf("Palindrome Word");
}
else
{
printf("Not Palindrome Word");
}
return 0;
}
Output
Enter a String: madam Palindrome Word