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)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.