#include<stdio.h>
#include<stdlib.h>
int main()
{
int cj[3][10], i, j;
int aver[3] = { 0,0,0 }, s = 0;
for (i = 0; i <= 2; i++)
for (j = 0; j <= 9; j++)
scanf("%d", &cj[i][j]);//首先用循环输入10个人的所有成绩
for (i = 0; i <= 2; i++)
for (j = 0; j <= 9; j++)
aver[i] = aver[i] + cj[i][j];//用循环分别得到3门单科成绩的总和
for (i = 0; i < 3; i++)
{
aver[i] = aver[i] / 10;//分别求出三门单科成绩的平均值
for(i=0;i<=2;i++)
{
printf("lesson%d:%d", i, aver[i]);//分别输出三门单科成绩的平均值
s = s + aver[i];//将三门单科成绩的平均值相加
}
printf("\naverage=%d", s / 3);//求各科总平均成绩
system("pause");
}
Before writing code, you must first understand the meaning of the question and know the process.
The average score of a single subject: refers to the average score of 10 people in the same subject. The average of three subjects in total is required.
Total average score of each subject: Add the average scores of the three individual subjects and divide by 3.