Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1Total ← Total + Marks[Row, Column] | AAdds the current element of the 2D array to the running total inside the nested loops | |
| 2FOR Row ← 1 TO 3 Total ← 0 FOR Column ← 1 TO 4 | BTotal ← 0 FOR Row ← 1 TO 3 FOR Column ← 1 TO 4 Total ← Total + Marks[Row, Column] | |
| 3For a column total, swap the loop order so the outer loop is Column and the inner loop is Row | CTotal ← 0 is placed before the loops, so the row totals keep growing. Each row total includes all the earlier rows. Move Total ← 0 inside the outer loop. | |
| 4For a grand total of the whole array, set Total to 0 once, before both loops | DResets the total to 0 for each new row, so every row gets its own total | |
| 5FOR Row ← 1 TO 3 FOR Column ← 1 TO 4 Total ← 0 Total ← Total + Marks[Row, Column] | EFOR Column ← 1 TO 4 Total ← 0 FOR Row ← 1 TO 3 Total ← Total + Marks[Row, Column] | |
| 6Total ← 0 FOR Row ← 1 TO 3 FOR Column ← 1 TO 4 Total ← Total + Marks[Row, Column] OUTPUT Total | FTotal ← 0 is inside the inner loop, so it is reset for every element and only the last element is kept. Move it to just after the outer FOR line, before the inner loop. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
Total ← Total + Marks[Row, Column] — Adds each element to a running total inside nested loops. Set Total to 0 first: before the loops for a grand total, or inside the outer loop for each row or column total.Total ← 0
FOR Column ← 1 TO 4
Total ← Total + Marks[Row, Column]FOR Column ← 1 TO 4
Total ← 0
FOR Row ← 1 TO 3FOR Row ← 1 TO 3
FOR Column ← 1 TO 4
Total ← Total + Marks[Row, Column] NEXT Column
OUTPUT Total
NEXT RowTotal ← 0
FOR Row ← 1 TO 3
Total ← Total + Marks[Row, Column]