2210/22/O/N/24 question 7: worked solution (October/November 2024, paper 22)

Show as plain text

Cambridge O Level Computer Science 2210 · 7.7 Trace tables Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8. Q61 2210/22/O/N/24 original Q7 Structured · 8 marks Worked solution (a) Run the REPEAT loop one input at a time. Answer starts as Value and is multiplied by Count from Value - 1 down to 1. Input -1 ends the algorithm, so 20, 9 and 4 are never read. Value Count Answer OUTPUT 5 5 4 20 3 60 2 120 1 120 120 6 6 5 30 4 120 3 360 2 720 1 720 720 -1 Value column correct [1] Count column correct [1] Answer column correct down to the first OUTPUT (120) [1] Answer column correct for the remaining rows [1] OUTPUT column correct [1] (b) It works out the factorial of the input number: it multiplies the number by each whole number below it until 1 (for example 5 × 4 × 3 × 2 × 1). [1] (c) The loop would never end properly. Write two of these: The program would accept the value and enter the FOR loop [1] Count would keep going down by 1 and never reach 1 , because it starts below 1, so there is an endless loop [1] KEY IDEA Trace each loop pass in order, and remember a FOR loop counting down needs a start value above its end value. TOTAL 8 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.