Palindromes date back at least to 79 CE, as a palindrome was found as a graffito at Herculaneum, a city buried by ash in that year. This palindrome, called the Sator Square, consists of an entire sentence written in Latin: "Sator Arepo Tenet Opera Rotas" ("The sower Arepo holds works wheels"). It is remarkable for the fact that the first letters of each word form the first word, the second letters form the second word, and so forth. Hence, it can be arranged into a word square that reads in four different ways: horizontally or vertically from either top left to bottom right or bottom right to top left.
So, this is the source code, I use C Language programming
#include <stdio.h>
#define TRUE 1
#define FALSE 0
int main(void) {
char str[80];
int i, j, pal;
printf("input string: ");
gets(str);
i = 0;
j = strlen(str) - 1;
pal = TRUE;
do {
if(str[i] != str[j])
pal = FALSE;
} while (str[i] == str[j] && i++ <= j--);
if(pal)
printf("> palindrom");
else
printf("> not a palindrom");
return 0;
}
0 comments
Post a Comment