微信公开课小程序热门讨论「求一个C语言结构体编程例子。」最新回复-排序你可以用最简单的冒泡或者选择排序,以平均分为标准#includestdio.htypedefstructstudent{intnum;charname[20];intScore1;intScore2;intScore3;floataverage;}student;studentst[3];voidCreateStudent(studentst[]){inti,j;floatAverage;for(i=0;i3;i++){printf(请输入学生%d的资料:
,i+1);printf(学号为:);scanf(%d,&st[i].num);printf(姓名是:);scanf(%s,&st[i].name);printf(第1门成绩是:);scanf(%d,&st[i].Score1);printf(第2门成绩是:);scanf(%d,&st[i].Score2);printf(第3门成绩是:);scanf(%d,&st[i].Score3);printf(
);st[i].average=(st[i].Score1+st[i].Score2+st[i].Score3)/3;}}voidSortStudent(studentst[],intnLength){inti,j,max;studenttemp;for(i=0;inLength;i++){max=i;for(j=i+1;jnLength;j++){if(st[j].averagest[max].average)max=j;}if(max!=i){temp=st[i];st[i]=st[max];st[max]=temp;}}}intmain(){intj;CreateStudent(st);SortStudent(st,3);printf(学号 姓名 语文 数学 英语 平均分
);for(j=0;j3;j++){printf(%d,st[j].num);printf( %s,st[j].name);printf( %d,st[j].Score1);printf( %d,st[j].Score2);printf( %d,st[j].Score3);printf( %2f,st[j].average);printf(
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
);}}
#includestdio.hstructstudent{intnum;charname[20];intScore1;intScore2;intScore3;}student[2];intmain(){inti,j;intAverage;for(i=0;i3;i++){printf(请输入学生%d的资料:
,i+1);printf(学号为:);scanf(%d,&student[i].num);printf(姓名是:);scanf(%s,&student[i].name);printf(第1门成绩是:);scanf(%d,&student[i].Score1);printf(第2门成绩是:);scanf(%d,&student[i].Score2);printf(第3门成绩是:);scanf(%d,&student[i].Score3);printf(
);}printf(学号 姓名 语文 数学 英语 平均分
);for(j=0;j3;j++){Average=(student[j].Score1+student[j].Score2+student[j].Score3)/3;printf(%d,student[j].num);printf( %s,student[j].name);printf( %d,student[j].Score1);printf( %d,student[j].Score2);printf( %d,student[j].Score3);printf( %d,Average);printf(
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
);}} 更多有关「求一个C语言结构体编程例子。」的疑问请扫码关注微信公开课+小程序!了解更多