求助解答一道C语言编程题

如题:从键盘上输入5个字符串(约定:每个字符串中字符数≤80字节),对其进行升序排序并输出。编程可用素材:printf("Input5strings:\n")...、pr... 如题:
从键盘上输入5个字符串(约定:每个字符串中字符数≤80字节),对其进行升序排序并输出。编程可用素材:printf("Input 5 strings:\n")...、printf("---------------------------\n")...。
程序的运行效果应类似地如图1所示,图1中的
hello
my
friend
Are you ready?
help!
是从键盘输入的内容。
展开
 我来答
匿名用户
2010-07-20
展开全部
//---------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
int i;
char at[5][80];
printf("Input 5 strings:\n");
for (i = 0; i<5; i++) {
scanf("%80[^\n]",at[i]);
fflush(stdin);
}
printf("---------------------------\n");
qsort(at,5,sizeof(char)*80,(int (*)(const void *,const void *))strcmp);
for (i = 0; i<5; i++)
printf("%s\n",at[i]);

return 0;
}
//---------------------------------------------------------------------------
gphone2008
2010-07-20 · TA获得超过380个赞
知道小有建树答主
回答量:224
采纳率:100%
帮助的人:156万
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv) {
int i,j;
char buff[5][80]={"","","","",""}, temp[80]="";
printf("Input 5 strings:\n");
fflush(stdout);
for (i=0;i<5;i++)
{
gets(buff[i]);
}
// 1. 最慢排序
// for (i=0; i<5; i++)
// for (j=i;j<5;j++)
// {
// if (strcmp(buff[i], buff[j])>0)
// {
// strcpy(temp,buff[i]);
// strcpy(buff[i], buff[j]);
// strcpy(buff[j], temp);
// }
// }

// 2. 快速排序
qsort(buff, 5, 80, strcmp);

printf("--------------------\n");
for (i=0; i<5; i++)
{
printf("%s\n", buff[i]);
}
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友a30bf3a
2010-07-20 · TA获得超过1180个赞
知道小有建树答主
回答量:480
采纳率:0%
帮助的人:377万
展开全部
#include <stdio.h>
#include <string.h>

void main()
{
char proname[5][80];
int i;

printf("Input 5 strings:\n");
for(i = 0; i < 5; i++)
gets(proname[i]);

qsort(proname, 5, 80, strcmp);

printf("---------------------------\n");
for(i = 0; i < 5; i++)
puts(proname[i]);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
水珠步雨华
2020-01-23 · TA获得超过3777个赞
知道小有建树答主
回答量:3106
采纳率:26%
帮助的人:422万
展开全部
//---------------------------------------------------------------------------
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
int
main(void)
{
int
i;
char
at[5][80];
printf("Input
5
strings:\n");
for
(i
=
0;
i<5;
i++)
{
scanf("%80[^\n]",at[i]);
fflush(stdin);
}
printf("---------------------------\n");
qsort(at,5,sizeof(char)*80,(int
(*)(const
void
*,const
void
*))strcmp);
for
(i
=
0;
i<5;
i++)
printf("%s\n",at[i]);
return
0;
}
//---------------------------------------------------------------------------
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式