永发信息网

输入5个国家的名字,然后按从小到大的顺序输出

答案:3  悬赏:50  手机版
解决时间 2021-03-02 20:51
  • 提问者网友:你挡着我发光了
  • 2021-03-02 02:26
输入5个国家的名字,然后按从小到大的顺序输出
最佳答案
  • 五星知识达人网友:第幾種人
  • 2021-03-02 03:58
for (i=0; i<5; i++) {
for(j=0;j<5-i;j++){
5改4
if (strcmp(str[i],str[i+1])>0) {
i改j
全部回答
  • 1楼网友:白昼之月
  • 2021-03-02 05:28
只写出了排序的算法,其他自己完善下就可以了,用的冒泡排序:
for (i=0; i<5; i++) {
for(j=0;j<5-i-1;j++){
if (strcmp(str[j],str[j+1])>0) {
char temp[15];
strcpy(temp,str[j]);
strcpy(str[j],str[j+1]);
strcpy(str[j+1],temp);
}
}
  • 2楼网友:轮獄道
  • 2021-03-02 04:05
#include
#include
int main ()
{
char str[5][15];
int i = 0;
for (i=0; i<5; i++) {
scanf("%s",str[i]);
}

int j = 0;
// 冒泡排序
for (i=0; i<(5-1); i++) {
for(j=i+1;j<5;j++){
if (strcmp(str[i],str[j])>0) {
char temp[15];
strcpy(temp,str[j]);
strcpy(str[j],str[i]);
strcpy(str[i],temp);
}
}
}

for (i=0; i<5; i++) {
puts(str[i]);

}
return 0;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯