A palindrome is a word, phrase, number or other sequence of characters which reads the same backward and forward. Write a C program that enter a word, store it in an array and determine whether it is palindrome or not.
Example : CIVIC is a palindrome
HOT is a not a palindrome
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char str[256];
int n, i;
int isPalindrome=1;
scanf("%s", str);
n = strlen(str);
for (i=0; i<n/2; i++) {
if (tolower(str[i]) != tolower(str[n-1-i])) {
isPalindrome = 0;
break;
}
}
printf("Word \"%s\" %s a palindrome\n", str,
isPalindrome ? "is" : "is not");
return 0;
}
Comments
Leave a comment