#include<stdio.h>
struct students
{
int num;
char name[10];
float math;
float eng;
float cy;
}
double average(float a,float b,float c)
{
double aver ;
aver=(a+b+c)/3;
return aver;
}
void sort(struct students a[3],double aver[3])
{
int i,j;
double t;
FILEfg;
fg=fopen("score_aver . txt","w");
for(i=0;i<2;i++ )
for(j=0;j<3-i;j++)
if(aver[i]<aver[j])
{
t=aver[i];
aver[i]=aver[j];
aver[j]=t;
}
for(i=0;i<3;i++)
{
fprintf(fg,"%d%s%f%f%f%lf",a[i].num,a[i].name ,a[i].math,a[i].eng ,a[i].cy ,aver[i]);
printf("%d%5%f%f%f%lf",a[i] .nun,a[i].name ,a[i].math,a[i].eng,a[i].cy,aver[i]);
}
fclose(fg);
}
int main()
{
struct students a[3];
int i;
double aver[3]={0};
FILEfp, *fg ;
fp=fopen("score.txt" ,"r");
fg=fopen("'score_ aver txt","w");
fprintf(fg,"姓名 高数 英语 c语言 平均分");
printf("姓名 高数 英语 c语言")
for(i=0;i<3;i++)
{
fscanf(fp ,"%d%s%f%f%f" ,&a[i] .num,&a[i].name ,&a[i].math,&a[i] .eng ,&a[i].cy);
aver[i]=average(a[i] math,a[i].eng,a[i].cy);
}
sort(struct students a[3],aver[3]);
fclose(fp);
fclose(fg);
return 0;
}