Question: Summing the Columns of a Two-Dimensional Array Sometimes you may need to calculate the sum of each column in a two-dimensional aray In the grevious
Summing the Columns of a Two-Dimensional Array Sometimes you may need to calculate the sum of each column in a two-dimensional aray In the grevious example a two-dimensional array is used to hold a set of test scones for a set of students. Suppose you wish to calculate the class average for cach of the test scores To do this, you calculate the average of each column in the array. This is accomplished with a set of nested loops. The outer loop controls the column subscript and the inner loop controls the row subscript. The inner loop calculates the sum of a column, which is stored in an accumulator. The following code demonstrates. const int NUM STUDENTS 3 const int NUN SCORES 53 double double average) double scores(NUM STUDENTS(MUN SCORES) ((88, 97, 79, 86, 94). /Nusber ot students /Mumber of test scores /hecumalator is set in the loops 1/ To hold each score's class average total: (86, 91, 78, 79, 84), (82, 73, 77, 82, 89)) #Get the class average for each score. for (int col 0: col
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
