7.5k views
3 votes
Given the following declaration: int j; int sum; double sales[10][7]; which of the following correctly finds the sum of the elements of the fourth column of sales?

1) sales[3][0] + sales[3][1] + sales[3][2] + sales[3][3] + sales[3][4] + sales[3][5] + sales[3][6]
2) sales[0][3] + sales[1][3] + sales[2][3] + sales[3][3] + sales[4][3] + sales[5][3] + sales[6][3] + sales[7][3] + sales[8][3] + sales[9][3]
3) sales[0][4] + sales[1][4] + sales[2][4] + sales[3][4] + sales[4][4] + sales[5][4] + sales[6][4] + sales[7][4] + sales[8][4] + sales[9][4]
4) sales[4][0] + sales[4][1] + sales[4][2] + sales[4][3] + sales[4][4] + sales[4][5] + sales[4][6]

1 Answer

3 votes

Final answer:

The correct option to find the sum of the elements of the fourth column of the 'sales' array is option 3.

Step-by-step explanation:

The correct option to find the sum of the elements of the fourth column of the 'sales' array is option 3) sales[0][4] + sales[1][4] + sales[2][4] + sales[3][4] + sales[4][4] + sales[5][4] + sales[6][4] + sales[7][4] + sales[8][4] + sales[9][4].

This option correctly accesses the elements in the fourth column of the 'sales' array by keeping the column index constant and varying the row index from 0 to 9.

The other options are either accessing elements from the wrong column or from the wrong row.

User Triggs
by
7.7k points