Putting it together
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Putting it together
- A real algorithm joins the pieces: arrays, loops and selection.
- The exam's standard methods are totalling, counting, linear search, and finding the maximum or minimum.
Total ← 0
FOR i ← 1 TO 5
Total ← Total + A[i]
NEXT i
OUTPUT Total
Explore
Totalling an array
Totalling — start at 0, then add each array item as the loop visits it.
Searching and counting
- Linear search: check each item, and set a flag if you find the target.
- Counting: add 1 to a counter each time a rule is true.
Found ← FALSE
FOR i ← 1 TO 5
IF A[i] = Target THEN
Found ← TRUE
ENDIF
NEXT i
Common mistakes
- Plan the structure before you write the pseudocode.
- Match the exam's keywords and layout exactly.
Now you try
- Each task uses an array that is filled for you — write the algorithm.
- Press Check answer to test it.
The array A is filled for you. Total all 5 values and output Total = then the total (it is 25).
Click Run to see the output here.
The array A is filled for you. Use a linear search to set Found to TRUE if 9 is in the array, then output Found.
Click Run to see the output here.
The array A is filled for you. Count how many values are greater than 4, then output the count (it is 3).
Click Run to see the output here.