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

1401
2024/4/18 17:10:47
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

}

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: c语言数组如何初始化