(C++) CPP Programs - 20
Friday, December 14, 2007
20. Write a C program to read a string and check whether it is palindrome or not (without using library functions). Output the given string along with suitable messages.
/*Palindrome*/
#include
#include
void main()
{
char word[56];
int n=0,i,j,palin;
clrscr();
printf("Enter a word\n\a");
gets(word);
while(word[n]!='\0')
n++;
i=0;
j=n-1;
palin=1;
while(i < j)
{
if(word[i]!=word[j])
{
palin=0;
break;
}
i++;
j--;
}
if(palin==1)
printf("%s is a palindrome\n\a",palin);
else
printf("%s is not a palindrome\n\a");
getch();
}
0 comments:
Post a Comment