使用C语言编写回文词游戏
lewis
2019-11-25
20次阅读
#include <stdio.h> #include <string.h>
int main() { char word[100]; printf(“Enter a word: “); scanf(”%s”, word);
int length = strlen(word);
int isPalindrome = 1;
for (int i = 0; i < length / 2; i++) {
if (word[i] != word[length - i - 1]) {
isPalindrome = 0;
break;
}
}
if (isPalindrome) {
printf("The word is a palindrome!\n");
} else {
printf("The word is not a palindrome.\n");
}
return 0;
}

发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。