该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
typedef struct { char name[20];
long xuehao; //struct student ==stu;
float score[4];
float sum;
float ave;
}stu;
int main(void)
{
int i,j,n;
stu *p;
stu temp;
printf("输入学生的数量 n:\n");
scanf("%d",&n);
p = (stu *)malloc(sizeof(stu)*n);
printf("依次输入学生的姓名 学号 四门功课的成绩\n");
for(i = 0;i < n;i++)
{
fflush(stdin);
gets(p[i].name);
scanf("%ld",p[i].xuehao);
getchar();
for(j = 0;j < 4;j++)
{
scanf("%f",p[i].score[j]);
}
}
for(i = 0;i < n;i++)
{
p[i].sum = p[i].score[0] + p[i].score[1] + p[i].score[2] + p[i].score[3];
p[i].ave = p[i].sum / 4;
}
for(i = 0;i < n-1;i++)
{
for(j = i+1;j < n;j++)
{
if(p[i].sum > p[j].sum)
{
temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}
free(p);
system("pause");
return 0;
}