C语言 判断字符串是否为回文
正读反读都一样的字符串为回文字符串,如“abcba”、“2002”。
#include <stdio.h> int main() { //定义变量 char str[51]; int i=0,count=0,flag=1; //输入字符串 printf("请输入一串字符串:\n"); scanf("%s",str); //统计字符串长度 while(str[i++]) count++; //判断是否为回文 for(i=0;i<count/2;i++) { if(str[i]!=str[count-1-i]) flag=0; } //输出结果 if(flag==0) printf("不是回文\n"); else printf("是回文\n"); return 0; }