Question: Program in C++ Summing the Columns of a Two-Dimensional Array Sometimes you may need to calculate the sum of each column in a two-dimensional array

Summing the Columns of a Two-Dimensional Array Sometimes you may need to calculate the sum of each column in a two-dimensional array In the previous example a two-dimensional array is used to hold a set of test scores for a set of students. Suppose you wish to calculate the class average for each 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 - 37 1/ Number of students const int NUM_SCORES 57 // Number of test scores double total; 11 Accumulator is set in the loops double average; // To hold each score's class average double scores NUM_STUDENTS (NUM_SCORES) = {{88, 97, 79, 86, 94). (86, 91, 78, 79, 84), (82, 73, 77, 82, 89}); 1/ Get the class average for each score. for (int col = 0; col
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
