c语言 求助

2024-12-28 16:15:51
推荐回答(4个)
回答1:

1

程序错误很多啊,
1.#includ 改为#include //拼写错误
2.包含头文件 #include//strcmp函数需要包含此头文件
3.vodi main() 改为void main() //拼写错误
4.ch[3][15]={"morning","afternoon","night","evening"};
改为ch[4][15]={"morning","afternoon","night","evening"}; //4个字符数组,3个保存不下
5.printf("%s\n",name[k];) 改为printf("%s\n",name[k]);//分号位置错误

答案是:
afternoon
evening
morning
night

-----------------------------
2
C

-----------------------------
3
函数指针

回答2:

源程序应该是这样的吧?
#include
#include

void func(char *a[],int n)
{
int i,j,l;char *temp;
for(i=0;i {
l=i;
for(j=i+1;j {
if(strcmp(a[j],a[l])<0) l=j;
if(l!=i)
{
temp=a[i];
a[i]=a[l];
a[l]=temp;
}
}
}
}
void main ()
{
char *name[4],ch[4][15]={"morning","afternoon","night","evening"};
int k;
for(k=0;k<4;k++)
name[k]=ch[k];
func(name,4);
for(k=0;k<4;k++)
printf("%s\n",name[k]);
}
答案是:
afternoon
evening
morning
night
Press any key to continue

回答3:

函数指针吧

回答4: