#include <stdio.h>
#include <string.h>
struct STUDENT {
char name[20];
int age;
float chinese,math,average;
};
#define N 5
void sort(struct STUDENT a[]);
main()
{
int i,count=0;
struct STUDENT a[N];
printf("please input the information: \n");
while(count<N)
{
printf("please input the name:");
//输入提示,虽然看起来很长,但是可以提示输入的内容
scanf("%s",a[count].name);
printf("please input age,chinese and math :");
scanf("%d%f%f",&a[count].age,&a[count].chinese,&a[count].math);
a[count].average=(a[count].chinese+a[count].math)/2;
count++;
}
sort(a);
//调用排序
for(i=0;i<N;i++)
//打印程序
printf("%s\t%f\n",a[i].name,a[i].average);
}
void sort(struct STUDENT a[])
//排序算法(冒泡法),貌似效率不是很高
{
int i,j;
struct STUDENT temp;
for(i=0;i<N;i++)
for(j=i;j<N;j++)
if(a[j].average>a[i].average)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}