#include<stdio.h>
#include<string.h>
main()
{
struct STUDENT
{
char name[80];
int age;
float chinese;
float math;
float average;
}a[5];
int i,j,k;
float max;
struct STUDENT temp;
for(i=0;i<5;i++)
{
a[i].average=0;
scanf("%s%d%f%f",a[i].name,&a[i].age,&a[i].chinese,&a[i].math);
a[i].average+=(a[i].chinese+a[i].math)/2;
}
for(i=0;i<4;i++)
{
max=a[i].average;
k=i;
for(j=i;j<=4;j++)
{
if(a[j].average>max)
k=j;
}
if(k!=i)
{
strcpy(temp.name,a[k].name);
temp.age=a[k].age;
temp.chinese=a[k].chinese;
temp.math=a[k].math;
temp.average=a[k].average;
strcpy(a[k].name,a[i].name);
a[k].age=a[i].age;
a[k].chinese=a[i].chinese;
a[k].math=a[i].math;
a[k].average=a[i].average;
strcpy(a[i].name,temp.name);
a[i].age=temp.age;
a[i].chinese=temp.chinese;
a[i].math=temp.math;
a[i].average=temp.average;
}
}
printf("姓名\t年龄\t语文\t数学\t平均分\n");
for(i=0;i<=4;i++)
{
printf("%s\t%d\t%.2f\t%.2f\t%.2f\n",a[i].name,a[i].age,a[i].chinese,a[i].math,a[i].average);
}
return 0;
}
温馨提示:内容为网友见解,仅供参考