标题:关于从小到大输出问题
取消只看楼主
宇智波曌
Rank: 2
等 级:论坛游民
帖 子:98
专家分:15
注 册:2011-4-17
结帖率:100%
 问题点数:0 回复次数:2 
关于从小到大输出问题
void main()
{
    struct staff sta[10]={
    {"201060001","Zhao"},
    {"201060005","Wang"},
    {"201060002","Qian"},
    {"201060003","Sun"},
    {"201060004","Li"},
    {"201060007","Wu"},
    {"201060006","Zhou"},
    {"201060010","Shen"},
    {"201060008","Zhen"},
    {"201060009","Jiang"}
    };
我要将学号从小到大输出,怎么输出啊?
搜索更多相关主题的帖子: void 
2011-05-29 22:05
宇智波曌
Rank: 2
等 级:论坛游民
帖 子:98
专家分:15
注 册:2011-4-17
得分:0 
结贴吧
2011-05-30 12:55
宇智波曌
Rank: 2
等 级:论坛游民
帖 子:98
专家分:15
注 册:2011-4-17
得分:0 
回复 3楼 lz1091914999
程序代码:
#include<stdio.h>
#include <string.h>

struct student
{
char num[20];
char name[20];

};
void main()
{
    struct student stu[10]={
    {"201060010","Shen"},
    {"201060002","Qian"},
    {"201060009","Jiang"},
    {"201060003","Sun"},
    {"201060005","Wang"},
    {"201060006","Zhou"},
    {"201060004","Li"},
    {"201060008","Zhen"},
    {"201060007","Wu"},
    {"201060001","Zhao"}
    };
    char a[10][300],temp[300];
    int i,j;
    for(i=0;i<10;i++)
        printf("%s      %s\n",stu[i].num,stu[i].name);
    for(i=0;i<10;i++)
        for(j=i+1;j<10;j++)
        {
            if(strcmp(stu[i].num,stu[j].num)>0)
            {
                strcpy(temp,stu[i].num);
                strcpy(stu[i].num,stu[j].num);
                strcpy(stu[j].num,temp);
            }
         }
   printf("====================================================\n");
     printf("Results:\n\n");
    for(i=0;i<10;i++)
    {
        printf("%s      \n",stu[i].num);
        
    }

}
你知道怎么把对应的姓名输出来吗?知道的话麻烦帮我写一下,先谢啦
2011-05-30 13:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-341374-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.082547 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved