C program to check whether the given string or word is a Palindrome or not:
#include<stdio.h>
#include<string.h>
int main()
{
int i,j=0,k;
char a[20];
printf("Enter a word to check whether its a palindrome.\n");
scanf("%s",a);
k=strlen(a);
for (i=0;i<k/2;i++)
{
if(a[i]==a[k-i-1])
; //empty statement.
else
{
j++;
break;
}
}
if(j>0)
printf("The word is not palindrome .\n");
else
printf("The word is palindrome .\n");
return 0;
}
Executing the program....
$demo
Enter a word to check whether its a palindrome.
abcba The word is palindrome .
No comments:
Post a Comment