温馨提示×

使用C语言编写回文词游戏

小樊
88
2024-04-26 17:10:47
栏目: 编程语言

#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;

}

0