此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
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)
English
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
探索
对数组累加求和
累加 —— 从 0 开始,循环每访问一个数组元素就把它加上。
English
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.
English
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
English
Common mistakes
- Plan the structure before you write the pseudocode.
- Match the exam's keywords and layout exactly.
English
Now you try
- Each task uses an array that is filled for you — write the algorithm.
- Press Check answer to test it.
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
数组 Values 已为你填好。把全部 5 个值相加,输出 Total = 再接总和(是 25)。
点击“运行”查看此处输出。
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
数组Values已为你填好。使用线性查找,如果9在数组中,就将Found设为TRUE,然后输出Found。
点击“运行”查看此处输出。
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
数组 Values 已为你填好。数一数有多少个值大于 4,然后输出这个数量(是 3)。
点击“运行”查看此处输出。