Current location - Health Preservation Learning Network - Slimming men and women - Four courses for three people, get the average score by person and subject respectively and output it (two-dimensional array in C language).
Four courses for three people, get the average score by person and subject respectively and output it (two-dimensional array in C language).
# contains "stdafx.h"

# include & ltiostream & gt

Use namespace std

int main()

{

int a[3][4]={{98,97,99,78},{ 100,67,89,98},{78,89,90,79 } }; //Define a two-dimensional array and initialize it.

int average_a[3],average _ b[4]; //Define two one-dimensional arrays and average them respectively.

int i,j;

float sum 1=0,sum 2 = 0; ?

//Find the average score of each student in four grades.

for(I = 0; I<3; i++)

{

for(j = 0; j & lt4; j++)

{

sum 1 = sum 1+a[I][j];

}

average _ a[I]= sum 1/4; //Use an array to save these average scores.

sum 1 = 0;

}

//Find the average score of three students in each subject.

for(j = 0; j & lt4; j++)

{

for(I = 0; I<3; i++)

{

sum 2 = sum 2+a[I][j];

}

average _ b[j]= sum 2/3;

sum 2 = 0;

}

//Let the three students be Liu, Li and. The four courses are advanced mathematics, English, C++ and psychology in turn.

The average scores of cout & lt& lt Liu and Li are

for(I = 0; I<3; i++)

{

cout & lt& ltaverage _ a[I]& lt; & ltendl

}

Cout & lt& lt "The average scores of advanced mathematics, English, C++ and psychology are:"

for(I = 0; I<4; i++)

{

cout & lt& ltaverage _ b[I]& lt; & ltendl

}

Returns 0;

}

Extended data:

1, C language is a process-oriented and abstract general-purpose programming language, which is widely used in bottom-level development. C language has the characteristics of high efficiency, flexibility, rich functions, strong expressive force and high portability, and is favored in programming.

2.c language compilers generally exist in various operating systems, such as Microsoft Windows, macOS, Linux, Unix, etc. The design of C language influenced many later programming languages, such as C++, Objective-C, Java, C# and so on.