用指针判断一个字符串是否为回文

2024-11-16 04:33:06
推荐回答(1个)
回答1:

int func(char *s)
{
char *p = s;
while(*p)p++;
p--;
while(*p == *s && p>s) p--,s++;
return p<=s;

int func(char *s)
{
char *p = s;
while(*p)p++;
p--;
while(*p == *s && p>s) p--,s++;
return p<=s;
}
int main()
{
char s[100];
scanf("%s",s);
if(func(s)) printf("%s是回文\n",s);
else printf("%s不是回文\n",s);
}