ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
5 marks · Testing and debugging
A logic error in the code means that an incorrect sequence is generated. The trace table below shows the line numbers where a variable has changed. Line Number sequence n 10 [0,0,0,0,0,0] 11 [5,0,0,0,0,0] 12 A 13 2 14 B 13 3 14 C State the missing values at A, B and C. A B C Re‑write Line 14 of the code to generate the correct sequence. A mathematician has written a program to generate the first six numbers in a mathematical sequence. The next number in the sequence is the sum of the previous two numbers. For example, if the sequence starts with 5,7, . . . Then the first six numbers of the sequence would be 5, 7, 12, 19, 31, 50 The following code has been developed to generate the sequence of six numbers. … Line 10 DECLARE sequence INITIALLY [0,0,0,0,0,0] Line 11 SET sequence[0] TO 5 Line 12 SET sequence[1] TO 7 Line 13 FOR n FROM 2 TO 5 DO Line 14 SET sequence[n] TO sequence[n] + sequence[n-1] Line 15 END FOR …
A= [5,7,0,0,0,0] B= [5,7,7,0,0,0] C= [5,7,7,7,0,0] 1 mark for each line sequence[n]=sequence[n-1] (1 mark) +sequence[n-2] (1 mark)