391,981 views
34 votes
34 votes
The HEIGHT variable will be used to hold the index numbers of the rows in a multidimensional array. The WIDTH will be used to hold the index numbers of the columns. Which of the following completed for loop could fill that previously declared anArray multidimensional array with the value 0 in each position?(a) for (int n=0; n < HEIGHT; n++) { for (int m=0; m < WIDTH; m++) { int anArray[0][0]; }}(b) for (int n=0; n < HEIGHT; n++) { for (int m=0; m < WIDTH; m++) { } anArray[n][m] = 0; }(c) for (int n=0; n < WIDTH; n++) { for (int m=0; m < HEIGHT; m++) { int anArray[n][m] = { {0,0,0}{0,0,0}{0,0,0}0,0,0{0,0,0}}; }}(d) for (int n=0; n < HEIGHT; n++) { for (int m=0; m < WIDTH; m++) { anArray[n][m] = 0; }}

User Sisyphe
by
2.8k points

1 Answer

10 votes
10 votes

Answer:

(d) for (int n=0; n < HEIGHT; n++) { for (int m=0; m < WIDTH; m++) { anArray[n][m] = 0; }}

Step-by-step explanation:

Given

HEIGHT
\to rows

WIDTH
\to columns

Required

Fill the array with zeros

Assume the array has already been declared

First, we iterate through the rows; using:

for (int
n=0;
n < HEIGHT;
n++) {

Next, we iterate through the columns

for (int
m=0;
m < WIDTH;
m++) {

Then we fill the array with the iterating variables of rows and the columns

anArray[n][m]

Lastly, close the loops

}}

User Alexandre Dion
by
2.9k points