Juntándolo todo
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.
![Values[1] to Values[5] hold 10 to 50; Total grows 10, 30, 60, 100, 150](/static/code/igcse-pseudocode/running-total.png)
DECLARE Values : ARRAY[1:5] OF INTEGER
DECLARE I, Total : INTEGER
FOR I ← 1 TO 5
Values[I] ← I * 10
NEXT I
Total ← 0
FOR I ← 1 TO 5
Total ← Total + Values[I]
NEXT I
OUTPUT Total
Sumar un array
Sumar — comenzar en 0, luego sumar cada elemento del array a medida que el bucle lo visita.
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.
DECLARE Values : ARRAY[1:5] OF INTEGER
DECLARE I, Target : INTEGER
DECLARE Found : BOOLEAN
FOR I ← 1 TO 5
Values[I] ← I * 10
NEXT I
Target ← 30
Found ← FALSE
FOR I ← 1 TO 5
IF Values[I] = Target
THEN
Found ← TRUE
ENDIF
NEXT I
OUTPUT Found
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.
Dificultad 3/5 · 200 monedas + un pequeño bono en el primer intento de hoy
El array Values está lleno para ti. Suma todos los 5 valores y muestra Total = seguido del total (es 25).
Haz clic en Ejecutar para ver la salida aquí.
Dificultad 3/5 · 200 monedas + un pequeño bono en el primer intento de hoy
El array Values está lleno para ti. Usa una búsqueda lineal para establecer Found como TRUE si 9 está en el array, luego muestra Found.
Haz clic en Ejecutar para ver la salida aquí.
Dificultad 3/5 · 200 monedas + un pequeño bono en el primer intento de hoy
El array Values está lleno para ti. Cuenta cuántos valores son mayores que 4, luego muestra el conteo (es 3).
Haz clic en Ejecutar para ver la salida aquí.