2(viii)
int X[][] = {{4, 5}, {7, 2}, {19, 4}, {7, 4}};
Write the index of the maximum element and the index of the minimum element of the array.
Show SolutionHide Solution↓
Maximum element index: X[2][0]
Minimum element index: X[1][1]
This is a 2D array (matrix) with 4 rows and 2 columns. Each element is accessed using X[row][column].
| Row | Column 0 | Column 1 |
|---|---|---|
| 0 | 4 | 5 |
| 1 | 7 | 2 |
| 2 | 19 | 4 |
| 3 | 7 | 4 |
To find the maximum element, all values in the array are compared. The largest value is 19, which is located in row 2 and column 0. Hence, its index is X[2][0].
To find the minimum element, all values are compared again. The smallest value is 2, which is located in row 1 and column 1. Hence, its index is X[1][1].