#include
#include
#include
#include
int main()
{int i,j,k;
struct student{
int id;
float s1,s2,s3,av;
}stu[11];
srand(time(NULL));
printf("初始成绩:\n");
for(i=1;i<11;i++)
{stu[i].id=2016000+i;
stu[i].s1=rand()%51+50;
stu[i].s2=rand()%51+50;
stu[i].s3=rand()%51+50;
stu[i].av=(stu[i].s1+stu[i].s2+stu[i].s3)/3.0;
printf("%d%7.1f%6.1f%7.1f%8.1f\n",stu[i].id,stu[i].s1,
stu[i].s2,stu[i].s3,stu[i].av);
}
for(i=1;i<10;i++) //冒泡排序的话交换数据太多,下面使用的是选择排序
{k=i;
for(j=i+1;j<11;j++)
if(stu[j].av>stu[k].av)k=j;
memcpy(&stu[0],&stu[k],sizeof(stu[0]));
memcpy(&stu[k],&stu[i],sizeof(stu[0]));
memcpy(&stu[i],&stu[0],sizeof(stu[0]));
}
printf("排序后的成绩:\n");
for(i=1;i<11;i++)
printf("%d%7.1f%6.1f%7.1f%8.1f\n",stu[i].id,stu[i].s1,
stu[i].s2,stu[i].s3,stu[i].av);
return 0;
}