#include
#include
main()
{ char a[100];
int i,j;
gets(a);
i=0;
j=strlen(a)-1;
while(i
{i++;j--;}
else
break;}
if(i>=j) printf("是回文.\n");
else printf("不是回文.\n");}
选自《C语言程序设计—从入门到进阶》,人民邮电出版社。
#include
#include
int main()
{char input[100] = {0};
int str_bound = 0; int i, res_ok = 1; printf("Enter a string.\n");
scanf("%s", input);
str_bound = strlen(input) -1; for (i = 0; i <= str_bound/2; i++) {
if (*(input + i) != *(input + str_bound -i)) { res_ok = 0;
break;
} }
if(res_ok) printf("YES\n");
else
printf("NO\n"); return 0;
}