Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Whichof the following answers correctly uses the for construct to initializeeach

ID: 3613302 • Letter: W

Question

Whichof the following answers correctly uses thefor construct

to initializeeach element of the tablearray in question 26 tothe

sum of itssubscripts. You can assume the integer variablesx and

y are declaredas control variables.

(a) for ( x = 0; x < arraySize; x++)

for ( y = 0; y < arraySize; y++ )

table[ x ][ y ] = x + y;

(b) for ( x = 0; x <= arraySize; x++)

for ( y = 0; y <= arraySize; y++ )

table[ x ][ y ] = x + y;

(c) for ( y = 0; y < arraySize; y++)

for ( x = 0; x < arraySize; x++ )

table[ x ][ y ] = x + y;

(d) (a) and (c)

(e)(b)

Explanation / Answer

(a) for ( x = 0; x < arraySize; x++ )

for ( y = 0; y < arraySize; y++ )

table[ x ][ y ] = x + y;

(b) for ( x = 0; x <= arraySize; x++)

for ( y = 0; y <= arraySize; y++ )

table[ x ][ y ] = x + y;

(c) for ( y = 0; y < arraySize; y++ )

for ( x = 0; x < arraySize; x++ )

table[ x ][ y ] = x + y;

(d) (a) and(c)