要判断一个字符串是否为回文字符串,可以采取以下步骤:
以下是一个简单的C语言程序示例,用于判断一个字符串是否为回文字符串:
#include <stdio.h>
#include <string.h>
int isPalindrome(char *str) {
int i = 0;
int j = strlen(str) - 1;
while (i < j) {
if (str[i] != str[j]) {
return 0;
}
i++;
j--;
}
return 1;
}
int main() {
char str[100];
printf("Enter a string: ");
scanf("%s", str);
if (isPalindrome(str)) {
printf("The string is a palindrome.\n");
} else {
printf("The string is not a palindrome.\n");
}
return 0;
}
在上面的程序中,isPalindrome
函数用于判断一个字符串是否为回文字符串。在main
函数中,用户输入一个字符串,然后调用isPalindrome
函数进行判断并输出结果。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:c语言怎么判断是不是回文字符串