#include<stdlib.h>
void InputScore(void);
int FindMaxScore(int n);
float AverageEachStu(int n);
float AverageEachCourse(int n,int i);
void Calculate(int n);
void DisplayScore(int i);
#define N 10
int main(void)
{
int i;
int score[N][5];
float averageStu[N];
float averageCourse[5];
int stu=0;
int maxstu;
for(stu=0;stu<N;stu++)
{
InputScore[stu];
Calculate[stu];
Display[stu];
}
maxstu=FindMaxScore(stu);
printf("得该课程最高分的人以及他的分数是%f\n",Display[maxstu]);
for(i=0;i<5;i++)
averageCourse[i]=AverageEachCourse(N,i);
printf("平均成绩是%f\n",averageCourse[i]);
return 0;
}
void IputScore(void)
{
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->name);
printf(\n输入成绩:);
gets(student->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,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)
{
int 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);
}
void 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);
}