急求一道c语言编程题!!

2024-11-26 21:47:49
推荐回答(2个)
回答1:

上面的回答太复杂了,我的答案:
#include
main()
{int i,j;
char a[100],c;
printf("please input a string:");
gets(a);
for(i=0;a[i]!='\0';i++);现将i加到比字符个数多一个
printf("the length of the syring is:%d\n",i--);i减一即为字符字数
for(j=0;j{c=a[j];a[j]=a[i];a[i]=c;}
puts(a);
getch();

}

回答2:

//---------------------------------------------------------------------------

#include

int strlen(char s[])
{
if (*s) return 1+strlen(s+1);
else return 0;
}

void strnz(char s[])
{
int i,len;
char c;
len=strlen(s);
for (i=0; i c=s[i];
s[i]=s[len-1-i];
s[len-1-i]=c;
}

}

int main(void)
{
int len;
char s[10];
scanf("%s",s);
strnz(s);
printf("%s",s);
return 0;
}
//---------------------------------------------------------------------------