//用结构体数组完成:有5个学生(包括学号,姓名,成绩),要求按照成绩高低输出学生信息 #include <stdio.h> struct Stu { int num; char name[20]; int score; }; int main() { int i,j; struct Stu student[5]={{317,"han",89},{318,"hu",50},{319,"kang",84},{320,"li",70},{321,"lian",76}}; struct Stu temp; for(i=0;i<5;i++) { for(j=i+1;j<5;j++) { if(student[i].score<student[j].score) { temp=student[i]; student[i]=student[j]; student[j]=temp; } } } for(i=0;i<5;i++) { printf("%d %6s %d\n",student[i].num,student[i].name,student[i].score); } return 0; }
【C语言】用结构体数组完成:有5个学生(包括学号,姓名,成绩),要求按照成绩高低输出学生信息
原文地址:http://blog.csdn.net/doudouwa1234/article/details/45030443