#include<stdio.h>
#include<stdlib.h>
void InputScore(int n);
int FindMaxScore(int n);
float AverageEachStu(int n);
float AverageEachCourse(int n,int i);
void Calculate(int n);
float DisplayScore(int i);
#define N 10
int score[N][5];
float averageStu[N];
float averageCourse[5];
int main(void)
{
int i;
int stu=0;
int maxstu;
for(stu=0;stu<N;stu++)
{
InputScore(stu);
Calculate(stu);
DisplayScore(stu);
}
maxstu=FindMaxScore(stu);
DisplayScore(maxstu);
printf("得该课程最高分的人以及他的分数是%f\n",DisplayScore(maxstu));
for(i=0;i<5;i++)
averageCourse[i]=AverageEachCourse(N,i);
printf("平均成绩是%f\n",averageCourse[i]);
return 0;
}
void IputScore(int i)
{
struct StudentScore
{
int num[30];
char name[30];
float score[30];
};
struct StudentScore student[N];
for(i=0;i<N;i++)
{
printf("\n请输入第%d个人的学号\n",i+1);
printf("输入姓名:");
gets(student[i].name);
printf("\n输入成绩:");
scanf("%f",&student[i].score);
}
}
int FindMaxScore(int n)
{
int max=0;
for(n=0;n<5;n++)
{
int i;
for(i=0;i<N;i++)
{
max=score[i][n]>score[max][n]?i:max;
}
}
return score[max][n];
}
float AverageEachStu(int n)
{
int i=0;
float sum=0;
for(n=0;n<N;n++)
{
for(i=0;i<5;i++)
sum+=score[n][i];
}
return sum/5;
}
float AverageEachCourse(int n,int i)
{
float sum=0;
for(i=0;i<5;i++)
{
for(n=0;n<N;n++)
sum+=score[n][i];
}
return sum/N;
}
void Calculate(int n)
{
int i;
for(n=0;n<N;n++)
averageStu[n]=AverageEachStu(n);
for(i=0;i<5;i++)
averageCourse[i]=AverageEachCourse(n,i);
}
float DisplayScore(int i)
{
struct StudentScore
{
int num[30];
char name[30];
float score[30];
float averageStu[30];
};
struct StudentScore student[N];
for(i=0;i<N;i++)
printf("\n%d\t\t\t%s\t\t\t%f\t\t\t%f\n",student->num,student->name,student->score,student->averageStu);
return 0;
}