How to write a C programme to check if a string is palindrome or not ?
Solution:
/* C programme to check if a string is palindrome or not */
/*Palindrome is a string*/
#include<stdio.h>
#include<string.h>
int main(void)
{
char a[999];
gets(a);
int x=strlen(a);
int counter=0;
int i;
for(i=0;i<=x;i++)
{
if(a[i]==a[x-1])
{
counter++;
x--;
}
}
if(i==counter)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return 0;
}
/*
Check if a string is palindrome or not.
Sample input: ulala
Sample output: NO
Sample input: abcba
Sample output: YES
*/