C语言在Get Ave Person函数中求每个人的三门课平均成绩,并输出 在Get Ave Lesson函数中求每门课的平均成绩,并输出 在Get Max函数中求每门课的最高成绩,并输出 在Get Min函数中求每门课的最低成绩,并输出
时间: 2024-03-06 11:48:04 浏览: 11
好的,我理解了你的问题。下面是我给出的C语言代码,实现了你所需的四个函数:
```c
#include <stdio.h>
#define N 3 // 人数
#define M 3 // 课程数
int scores[N][M]; // 成绩矩阵,scores[i][j]表示第i个人的第j门课的成绩
// 获取每个人的平均成绩,并输出
void GetAvePerson()
{
int sum, ave;
for (int i = 0; i < N; i++)
{
sum = 0;
for (int j = 0; j < M; j++)
{
sum += scores[i][j];
}
ave = sum / M;
printf("Person %d's average score is %d\n", i+1, ave);
}
}
// 获取每门课的平均成绩,并输出
void GetAveLesson()
{
int sum, ave;
for (int j = 0; j < M; j++)
{
sum = 0;
for (int i = 0; i < N; i++)
{
sum += scores[i][j];
}
ave = sum / N;
printf("Lesson %d's average score is %d\n", j+1, ave);
}
}
// 获取每门课的最高成绩,并输出
void GetMax()
{
int max;
for (int j = 0; j < M; j++)
{
max = scores[0][j];
for (int i = 1; i < N; i++)
{
if (scores[i][j] > max)
max = scores[i][j];
}
printf("Lesson %d's highest score is %d\n", j+1, max);
}
}
// 获取每门课的最低成绩,并输出
void GetMin()
{
int min;
for (int j = 0; j < M; j++)
{
min = scores[0][j];
for (int i = 1; i < N; i++)
{
if (scores[i][j] < min)
min = scores[i][j];
}
printf("Lesson %d's lowest score is %d\n", j+1, min);
}
}
int main()
{
// 输入成绩矩阵
printf("Please enter the scores of %d persons for %d lessons:\n", N, M);
for (int i = 0; i < N; i++)
{
printf("Person %d's scores: ", i+1);
for (int j = 0; j < M; j++)
{
scanf("%d", &scores[i][j]);
}
}
// 调用四个函数输出结果
GetAvePerson();
GetAveLesson();
GetMax();
GetMin();
return 0;
}
```
在主函数中,我先输入了成绩矩阵,然后调用了四个函数分别输出每个人的平均成绩、每门课的平均成绩、每门课的最高成绩和每门课的最低成绩。