IGCSE · Computer Science 0478 · Algorithms & programming

Algorithms & trace tables: IGCSE Computer Science questions with answers

Free Algorithms & trace tables questions for IGCSE Computer Science (0478), part of Algorithms & programming. Each question has the answer and the marking points an examiner would look for.

Generate a full Algorithms & Trace Tables worksheet →All Algorithms & programming questions

Algorithms & trace tables practice questions

Question 1Structured · 5 marks

The pseudocode below calculates the price of a cinema ticket.

(a)

State the output when the input is 80 then "G".

[1]
(b)

State the output when the input is 30 then "X".

[1]
(c)

Rewrite the CASE structure using IF statements, so that the program works in the same way.

[3]
Show answers and mark scheme
PartAnswer and marking pointsMarks
(a)68
68 B1
1
(b)30
30 B1
1
(c)IF Code = "S" THEN Discount ← 5 ELSE IF Code = "G" THEN Discount ← 15 ELSE Discount ← 0 ENDIF ENDIF
IF Code = "S" THEN Discount ← 5 B1
Nested IF / ELSE for Code = "G" giving Discount ← 15 B1
ELSE Discount ← 0 and correct ENDIFs B1
3
Question 2Structured · 6 marks

The pseudocode function below is part of a word-game program.

(a)

State the value returned by CountChar("MISSISSIPPI", 'S').

[1]
(b)

Give the identifier of one parameter and the identifier of one local variable in the function.

[2]
(c)

Explain why CountChar is written as a function rather than as a procedure.

[1]
(d)

Write a pseudocode statement that uses CountChar to output the number of times the letter E appears in the string variable Sentence.

[2]
Show answers and mark scheme
PartAnswer and marking pointsMarks
(a)4
4 B1
1
(b)parameter: Word / Letter; local variable: Count / Index
Word or Letter B1
Count or Index B1
2
(c)it returns a single value (the count) to the point where it is called
It returns a value (to the calling statement) B1
1
(d)OUTPUT CountChar(Sentence, 'E')
OUTPUT with a call to CountChar B1
Correct arguments Sentence and 'E' in the right order B1
2
Question 3Structured · 6 marks

The algorithm below is written in pseudocode.

(a)

Complete the trace table for the input 4599.

NumberDigitSumCountOUTPUT
459900
Table 3.1
[4]
(b)

Describe the purpose of this algorithm.

[2]
Show answers and mark scheme
PartAnswer and marking pointsMarks
(a)Output 27, 4
Number column correct B1
Digit column correct B1
Sum and Count columns correct B1
Output 27, 4 B1
4
(b)Adds up the digits of the number and counts how many digits it has
Adds up the digits B1
Counts the number of digits B1
2
Question 4Structured · 6 marks
(a)

Complete the trace table for the input data: 14, 18, 13, -1

NumTotalCountOUTPUT
Table 4.1
[4]
(b)

Identify the type of loop used and explain why it is suitable.

[2]
Show answers and mark scheme
PartAnswer and marking pointsMarks
(a)Output 15
Num column correct B1
Total column correct B1
Count column correct B1
Output 15 B1
4
(b)Pre-condition (WHILE) loop: the number of inputs is not known in advance / stops when −1 (rogue value) is input
Pre-condition / WHILE loop B1
Number of iterations not known in advance / rogue value B1
2
Question 5Structured · 4 marks

The algorithm should ask for a password and allow up to 3 attempts. The password is "Orchid7". It contains errors.

Identify the two errors in the algorithm and write a correction for each.

[4]
Show answers and mark scheme
PartAnswer and marking pointsMarks
line 4: Attempts ← Attempts - 1 → Attempts ← Attempts + 1; line 5: AND → UNTIL Password = "Orchid7" OR Attempts = 3
Error: line 4: Attempts ← Attempts - 1 B1
Correction: Attempts ← Attempts + 1 B1
Error: line 5: AND B1
Correction: UNTIL Password = "Orchid7" OR Attempts = 3 B1
4
Question 6Structured · 5 marks

Write an algorithm in pseudocode to input the temperatures (°C) recorded at a weather station on 25 days, and output the number of temperatures below 0 and the average temperature.

[5]
Show answers and mark scheme
PartAnswer and marking pointsMarks
Initialise Total and Count to 0; FOR 1 TO 25; INPUT value; add to Total; IF condition THEN Count ← Count + 1; NEXT; OUTPUT Count and Total / 25
Total and Count initialised to 0 B1
Loop that runs 25 times B1
INPUT inside the loop and value added to Total B1
IF Temp < 0 (or equivalent; not <=) THEN Count ← Count + 1 B1
Average = Total / 25 calculated after the loop and both outputs B1
5

More Algorithms & programming questions

Want a mentor, not just a paper?

Riyaz Shaikh has mentored IGCSE, IB and A Level students for 15+ years, one-on-one, online and in Mumbai. The hardest questions on this site are the ones he uses to find a student's weak points.

Meet Riyaz →

Original Cambridge-style practice questions written for mentorriyaz.in. These are not Cambridge past paper questions, and this site is not affiliated with or endorsed by Cambridge University Press & Assessment. Updated 2026-11-04. Paper generator · mentorriyaz.in