Computer Applications

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.

Java Arrays

2 Likes

Answer

Maximum element index: X[2][0]
Minimum element index: X[1][1]

Explanation

This is a 2D array (matrix) with 4 rows and 2 columns. Each element is accessed using X[row][column].

RowColumn 0Column 1
045
172
2194
374

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].

Answered By

1 Like


Related Questions