Putting it together · Juntando tudo
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.
Juntando tudo
- Um algoritmo real une as peças: arrays, loops e seleção.
- Os métodos padrão da prova são somatório, contagem, busca linear e encontrar o máximo ou mínimo.
DECLARE A : ARRAY[1:5] OF INTEGER
DECLARE I, Total : INTEGER
FOR I ← 1 TO 5
A[I] ← I * 10
NEXT I
Total ← 0
FOR I ← 1 TO 5
Total ← Total + A[I]
NEXT I
OUTPUT Total
Totalling an array · Somando um array
Totalling — start at 0, then add each array item as the loop visits it. · Soma — comece em 0, depois adicione cada item do array conforme o loop o 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.
Busca e contagem
- Busca linear: verifique cada item e defina uma flag se encontrar o alvo.
- Contagem: adicione 1 a um contador cada vez que uma regra for verdadeira.
DECLARE A : ARRAY[1:5] OF INTEGER
DECLARE I, Target : INTEGER
DECLARE Found : BOOLEAN
FOR I ← 1 TO 5
A[I] ← I * 10
NEXT I
Target ← 30
Found ← FALSE
FOR I ← 1 TO 5
IF A[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.
Erros comuns
- Planeje a estrutura antes de escrever o pseudocódigo.
- Corresponda exatamente às palavras-chave e ao layout da prova.
Now you try
- Each task uses an array that is filled for you — write the algorithm.
- Press Check answer to test it.
Agora você tenta
- Cada tarefa usa um array que é preenchido para você — escreva o algoritmo.
- Pressione Check answer para testá-lo.
The array A is filled for you. Total all 5 values and output Total = then the total (it is 25). · O array A já está preenchido. Some todos os 5 valores e saia com Total = depois o total (é 25).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
The array A is filled for you. Use a linear search · busca linear to set Found to · até TRUE if · se 9 is in the array, then output Found. · O array A já está preenchido. Use uma busca linear para definir Found como TRUE se 9 estiver no array, depois saia com Found.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
The array A is filled for you. Count how many values are greater than 4, then output the count (it is 3). · O array A já está preenchido. Conte quantos valores são maiores que 4, depois saia com a contagem (é 3).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.