#include stdiohint main char a5i; getsa; for int i = 0; i 5; ++i ifa0 == a4-i && a1 == a3-i printfs是回文串a; else printfs不是回文串a; 这个代码怎么修改成判断回
#include <stdio.h> #include <string.h>
int main() { char str[100]; printf("请输入一个字符串:"); fgets(str, 100, stdin); int len = strlen(str) - 1; // 因为fgets会把换行符读入,所以要减一
int flag = 1; // 标记是否为回文串
for (int i = 0; i < len / 2; i++) {
if (str[i] != str[len - i - 1]) { // 如果对应的字符不相等,则不是回文串
flag = 0;
break;
}
}
if (flag) {
printf("%s是回文串\n", str);
} else {
printf("%s不是回文串\n", str);
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/bWet 著作权归作者所有。请勿转载和采集!