求C语言,编写函数fun,功能是,判断字符串,是否是回文(123321类),是,函数返回1,否,返回0

2025-03-04 20:10:29
推荐回答(2个)
回答1:

#include
#include
int fun(char s[])
{ int b,i,t;
char a[100];

b=strlen(s);
t=b;
i=0;
while(i!=t)
{
a[i]=s[b-1];
b--;
i++;
}
a[i]='\0';
if(!strcmp(s,a))
return 1;
else
return 0;
}
void main()
{
char s[100];
int b,i,t;
printf("请输入字符串:");
scanf("%s",s);
i=fun(s);

if(i==1)
printf("这是回文串!\n");
else
printf("这不是回文串!\n");
}

回答2:

int fun (char* p, int n )
{
int i,j=0;
while(*p != 0){
if (*p != *(p+n-1)){
i=0;
continue;
}
p++;
j++;
}
if(j==n){
i = 1;
}
return i

}