C Source Codes List | Source Code Home
Program : Program to search for a palindrome.
/* Prg. to search for a palindrome */
#include
#include
#define EOL '\n'
#define TRUE 1
#define FALSE 0
void main()
{
char letter[80];
int tag,count,countback,flag,loop=TRUE;
clrscr();
while (loop)
{
flag=TRUE;
printf("\n\nPlease enter a word,phrase or sentence below(type END to exit the program):\n");
for (count=0;(letter[count]=getchar())!=EOL;++count)
;
if ((toupper(letter[0])=='E') && (toupper(letter[1])=='N') && (toupper(letter[2])=='D'))
break;
tag=count-1;
for ((count=0,countback=tag);count<=(tag/2);(++count,--countback))
{
if (letter[count]!=letter[countback])
{
flag=FALSE;
break;
}
}
for (count=0;count<=tag;++count)
putchar(letter[count]);
if (flag)
printf(" is a palindrome.");
else
printf(" is not a palindrome.");
}
}
C Source Codes List | Source Code Home
|
|