Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Finding the largest value in an array worksheet is part of the IGCSE Computer Science 0478 — 8.2 Arrays journey. Print it as a booklet?
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 | |
|---|---|---|
| 1Largest ← Marks[1] | AIF Marks[Index] < Smallest THEN | |
| 2IF Marks[Index] > Largest THEN | BLargestIndex ← Index | |
| 3To find the smallest value, use the same method but replace it when an element is smaller | CAssume the first element is the largest so far, before any comparing starts | |
| 4To know which element holds the largest value, store its index as well when you replace Largest | DLargest starts at 0 instead of the first element. If every mark were negative, 0 would wrongly stay as the answer. It should start as Largest ← Marks[1]. | |
| 5Largest ← 0 FOR Index ← 1 TO 10 IF Marks[Index] > Largest THEN Largest ← Marks[Index] ENDIF NEXT Index | ECheck whether the current element is bigger than the largest value found so far | |
| 6IF Marks[Index] > Largest THEN Largest ← Index ENDIF | FIndex is assigned to Largest instead of the element value. It should be Largest ← Marks[Index]. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
Largest ← Marks[1] — Start by assuming the first element is the largest, then compare every other element and replace Largest when a bigger one is found.Largest ← Marks[1]FOR Index ← 2 TO 10
IF Marks[Index] > Largest THEN
Largest ← Marks[Index]IF Marks[Index] > Largest THEN
Largest ← Marks[Index]
ENDIFIF Marks[Index] < Smallest THEN
Smallest ← Marks[Index]
ENDIFIF Marks[Index] > Largest THEN
Largest ← Marks[Index]
LargestIndex ← Index