#include <stdio.h>
#define N 10
struct student //第一步, 根据具体情况定义结构体类型。
{ double num; /*学号*/
float score[5]; //数组依次存放英语,数学,计算机基础及平均分
};
void input( struct student arr[ ], int ) ; /*函数原型*/
void aver ( struct student arr[ ], int );
void order( struct student arr[ ], int );
void output( struct student arr[ ], int ) ;
void main( )
{ struct student stu[100]; /* 定义结构体数组*/
printf("水利水电学院07级5班 宋戈 学号200731580148");
input( stu, N ) ; /*依次调用自定义函数*/
aver( stu, N ) ; order( stu, N ) ; output( stu, N ) ;
}
void input( struct student arr[ ], int n )
{ int i, j ;
printf("\nInput 学号,数学,英语,计算机基础\n");
for ( i=0 ; i<n; i++) //n名学生
{ scanf("%lf ", &arr[i].num);
for ( j=0 ; j<3 ; j++ )
scanf("%f", &arr[i].score[j]) ; /*输入三科成绩*/
}
}
void aver( struct student arr[], int n )
{ int i, j ;
for( i=0 ; i<n ; i++ ) //n名学生
{ arr[i].score[4]=0 ;
for ( j=0 ; j<3 ; j++ )
arr[i].score[4]+= arr[i].score[j];//求和
arr[i].score[3]=arr[i].score[4];
arr[i].score[4]=arr[i].score[4]/3 ; }
}
void order( struct student arr[ ], int n )
{ struct student temp ; int i, j ;
for( i=1 ; i<n ; i++ )
for( j=0 ; j<n-i ; j++ )
if ( arr[j].score[3]<arr[j+1].score[3] )
{ temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp ;}
}
void output( struct student arr[ ], int n )
{ int i, j ;
printf("* * * * * * * * * * * * * * * * * * * * * *\n");
printf("学号\t数学\t英语\t计算机\t总分\t平均\n") ;
for (i=0 ; i<n ; i++)
{ printf("%.0f\t", arr[i].num ) ;
for( j=0; j<5 ; j++ ) //输出三科成绩及平均成绩
printf("%.2f\t", arr[i].score[j] ) ;
printf("\n") ; }
}