C语言判断回文字符串
程序功能:输入一个字符串,判断其是否为回文字符串。
所谓回文字符串,是指从左到右读和从右到左读完全相同的字符串。
代码实现:
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char s[100];
int i,j,n;
printf("请输入字符串:");
gets(s);
n = strlen(s);
for (i = 0,j = n-1; i<j; i++,j--)
{
if (s[i] != s[j])
{
break;
}
}
if (i>=j)
{
printf("是回文字符串\n");
}
else
{
printf("不是回文字符串\n");
}
system("pause");
}