C语言,结构体题目,怎么做,求大神修改一下
已经修改完成:
#include<stdio.h>
#include<stdlib.h>
struct Student
{ int num;
char name[20];
char sex;
int age;
float chinese;
float math;
float english;
};
int main()
{ struct Student stu[4]=
{ {1,"zhangshan",'M',20,86.3,88.5,78.5},
{2,"lisi",'F',18,78.5,76.3,68.5},
{3,"wangwu",'M',19,90.2,85.6,84.6},
{4,"zhaoliu",'F',21,76.5,90.5,85.5}
};
int n=4;
int i;
int j;
struct Student temp;
for(i=n-1; i>0; i--)
{ for(j=0; j<i; j++)
{ if(stu[j].chinese<stu[j+1].chinese)
{ temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
}
}
for(i=0; i<n; i++)
printf("%2d%10s%2c%4d%6.2f%6.2f%6.2f\n",
stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].chinese,stu[i].math,stu[i].english);
printf("\n");
return 0;
}