#include <stdio.h>
#include <string.h>
struct student
{
char name[20];
long int num;
float score[4];
} ;
struct student stu[5]={{"aaa",10101,67.5,89,78,64},{"BBB",10102,77.5,90,58,69},{"CCC",10103,70.3,88,98,74},{"DDD",10104,73.5,86,88,64},{"EEE",10105,80.5,89,68,64}};
void main()
{
float M=0;
int m=0,k=0,D[5];
float total_score[5]={0};
for(int i=0;i<5;i++)
{ D[i]=1;
printf("%s %ld %f %f %f %f\n",stu[i].name,stu[i].num,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3]);
}
for( i=0;i<5;i++)
{
for (int j=0;j<4;j++)
{ M=stu[i].score[j];
total_score[i]=total_score[i]+stu[i].score[j];
if (M<60.0)
{
printf("\n学生%s的第%d门成绩不及格,不参加排名\n",stu[i].name,j+1);
D[i]=0;
}
}
}
// display the total score
printf("\n各个学生的总成绩为:\n");
for ( i=0;i<5;i++)
{
printf("%s %f \n",stu[i].name,total_score[i]);
}
// to sort the total score
for ( i=0;i<4;i++)
{
k=i;
if (D[i]==0)
{
continue;
}
else
for (int j=i+1;j<5;j++)
{
if (D[j]==0)
{
continue;
}
else
{ if(total_score[k]<total_score[j])
k=j;
}
}
float tep=0;
tep=total_score[i];
total_score[i]=total_score[k];
total_score[k]=tep;
struct student temp;
temp=stu[i];
stu[i]=stu[k];
stu[k]=temp;
}
printf("\n学生的总成绩排名为:\n");
for (i=0;i<5;i++)
{
if (D[i]==1)
{
m=m+1;
printf("the rank %d is %s\n",m,stu[i].name);
}
}
}