217k views
0 votes
Which of the following lines of code changes 9 to 4? Explain.

a. matrix[0][3] = 4;
b. matrix[1][3] = 4;
c. matrix[2][4] = 4;
d. None of the above.

User Drewmate
by
8.1k points

1 Answer

7 votes

Final answer:

The correct line of code to change 9 to 4 is matrix[0][3] = 4;

Step-by-step explanation:

The correct line of code that changes 9 to 4 is option a. matrix[0][3] = 4;

The reason why this line of code changes 9 to 4 is because it is accessing the element at the 0th row and 3rd column of the matrix and assigning it the value 4. In a matrix, the first index represents the row number and the second index represents the column number.

Option b, matrix[1][3] = 4;, would change an element in the second row, which is not the one we want to change. Option c, matrix[2][4] = 4;, is accessing an element that is outside the bounds of the matrix, as the indices start from 0. Therefore, option a is the correct choice to change 9 to 4.

User Purush Pawar
by
7.8k points