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 ← 0 Count ← 0 Max ← Mark[1] Min ← Mark[1] | ATotal is set to 0 inside the loop, so it is reset on every pass and ends up holding only the last item. It must be initialised before the loop. | |
| 2Average ← Total / Count | BInitialise every variable before the loop starts, with Max and Min set to the first item | |
| 3Inside the one loop, the total and the counter are both updated for every item | CThe average is calculated inside the loop, before all the items have been added, so it is worked out too early. It should be calculated once after NEXT i. | |
| 4Inside the same loop, maximum and minimum are updated using IF statements that compare each item | DTotal ← Total + Mark[i] Count ← Count + 1 | |
| 5FOR i ← 1 TO 5 Total ← 0 Total ← Total + Mark[i] NEXT i | ECalculate the average after the loop has finished, using the final total and count | |
| 6FOR i ← 1 TO 5 Total ← Total + Mark[i] Average ← Total / 5 NEXT i OUTPUT Average | FIF Mark[i] > Max THEN Max ← Mark[i] IF Mark[i] < Min THEN Min ← Mark[i] |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
single pass — One loop visits each item once, updating the total, count, maximum and minimum together. The average is worked out after the loop ends, as Total / Count.Total ← 0
Count ← 0
Max ← Marks[1]FOR i ← 1 TO 10
Total ← Total + Marks[i]
Count ← Count + 1IF Marks[i] > Max THEN
Max ← Marks[i]
ENDIFIF Marks[i] < Min THEN
Min ← Marks[i]
ENDIFNEXT i
Average ← Total / Count
OUTPUT Average