#include <stdio.h>
#define N 10
#define M 5
#define Q 30
struct STUDENT
{
int studentID;
float score[M];
};
struct STUDENT stu[N];
void Student_achievement_output(struct STUDENT *s);
void each_student_average(struct STUDENT *stu_score);
void each_course_average(struct STUDENT *sco_score);
void MAX(struct STUDENT *Max);
int main(void)
{
printf("struct STUDENT stu[%d] Number of bytes :%d\n", N, Q*sizeof(struct STUDENT));
putchar('\n');
struct STUDENT stu[N] = {{123401, {91.27, 92.39, 93.48, 94.36, 95.97}},
{123402, {90.97, 91.27, 92.39, 93.48, 94.36}},
{123403, {99.36, 98.97, 97.27, 96.39, 95.48}},
{123404, {91.48, 99.36, 92.36, 98.27, 93.39}},
{123405, {90.39, 91.48, 92.36, 93.97, 94.27}},
{123406, {99.11, 98.64, 97.93, 96.01, 95.55}},
{123407, {90.55, 91.11, 92.64, 93.93, 94.01}},
{123408, {99.01, 98.55, 97.11, 96.64, 95.93}},
{123409, {90.93, 91.01, 92.55, 93.11, 94.64}},
{123410, {99.64, 98.93, 97.01, 96.55, 95.11}}};
putchar('\n');
Student_achievement_output(stu);
putchar('\n');
each_student_average(stu);
putchar('\n');
each_course_average(stu);
putchar('\n');
MAX(stu);
return 0;
}
void Student_achievement_output(struct STUDENT *s)
{
int i=0;
int j=0;
printf("studentID:\tscore_1: score_2: score_3: score_4: score_5:");
putchar('\n');
for(i=0; i<N; i++)
{
putchar('\n');
printf(" %d ", s[i].studentID);
putchar('\t');
for(j=0; j<M; j++)
{ printf(" %.1f ", s[i].score[j]); }
putchar('\n');
}
}
void each_student_average(struct STUDENT *stu_score)
{
int i, j;
float sum = 0;
putchar('\n');
for(i=0; i<M; i++)
{
for(j=0; j<N; j++)
{ sum += stu_score[i].score[j]; }
printf("学号:%d, Average score: %.1f\n", stu_score[i].studentID, sum/5.0);
putchar('\n');
}
}
void each_course_average(struct STUDENT *sco_score)
{
int i, j;
float sum = 0;
putchar('\n');
for(j=0; j<M; j++)
{
for(i=0; i<N; i++)
{ sum += sco_score[i].score[j]; }
printf("sccore_%d, Average value: %.1f\n", j+1, sum/10.0);
putchar('\n');
}
}
void MAX(struct STUDENT *Max)
{
int i, j, m1, m2;
float max = 0;
for(i=0; i<N; i++)
{
for(j=0; j<M; j++)
{
if(Max[i].score[j] > max)
{
max = Max[i].score[j];
m1 = i;
m2 = j+1;
}
}
}
putchar('\n');
printf("max_score: %.3f\n", max);
printf("studentID: %d\n", Max[m1].studentID);
printf("score_%d\n ", m2);
putchar('\n');
}