Finding the largest value in an array
Start by assuming the first element is the largest, then compare every other element and replace Largest when a bigger one is found.
Understanding Finding the largest value in an array in IGCSE Computer Science Paper 2
What it does: Finding the smallest works like finding the largest, but the comparison is reversed from > to <. Inside the IF, saving the current Index in a second variable records the position of the largest value as well as the value itself. Starting with the first element works for any data. Starting at 0 fails if every mark is negative, and it does not use the array's own values. A new largest is found only when the current element is greater than Largest. Checking for equality finds duplicates, not bigger values. Element 1 is already in Largest, so the loop can start at 2. Index 0 is outside the bounds 1 to 5 and causes an index out of range error.
Common mistakes: Largest must hold a mark, not the loop counter. N is only the index. It should be Largest ← Marks[N]. A count-controlled loop uses the keyword TO, not UNTIL. It should be FOR N ← 2 TO 5.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 459–468) and word search (Modules 459–478).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
Largest ← Marks[1]Fill in the Blanks
Spot the Error
Student with a class code? Join your class →