#include "stdio.h"
#define N 30
/*定义N为总人数*/
struct student
{
char num[7];
float mid;
float final;
float sum;
float average;
};
void init(struct student *);
void sort(struct student *);
void result(struct student *);
main()
{
struct student stu[N];
init(stu);
sort(stu);
result(stu);
getch();
}
void init(struct student *stu)
/*输入原始数据:学号、期中成绩、期末成绩。并计算平均分、总分*/
{
int i;
printf("===========================Input===============================\n");
for(i=0;i<N;i++)
{
printf("Input stu %d(num mid final):",i+1);
scanf("%s%f%f",&stu[i].num,&stu[i].mid,&stu[i].final);
stu[i].sum=stu[i].mid+stu[i].final;
stu[i].average=stu[i].sum/2;
}
}
void sort(struct student *stu)
/*排序*/
{
int i,j;
struct student temp;
for(i=0;i<N-1;i++)
{
for(j=0;j<N-i-1;j++)
{
if(stu[j].average>stu[j+1].average)
{
temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
}
}
}
void result(struct student *stu)
/*输出结果*/
{
int i;
printf("===========================Result==============================\n");
printf("num
mid
final
sum
average\n");
for(i=0;i<N;i++)
{
printf("%s
%6.2f
%6.2f
%6.2f
%6.2f\n",stu[i].num,stu[i].mid,stu[i].final,stu[i].sum,stu[i].average);
}
}