结构体来给学生信息排序
#include "stdafx.h"
struct student
{
int num;
char name[30];
float score;
};
int main()
{
struct student stu [5]={{001,"dong",100},{003,"ma",59},{002,"qing",99},{004,"zhuang",18},{005,"ha",66}};
struct student temp;
int n=5;
int i,j,k;
printf(" the order is\n\n");
for (i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if (stu[j].score >stu[k].score)
{
temp=stu[k];
stu[k]=stu[j];
stu[j]=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("%6d %s %f\n",stu[i].num ,stu[i].name ,stu[i].score );
printf("\n");
}
return 0;
}