TK Study

Multiple choice › Algorithms (tracing)

Algorithms (tracing)

1. Algorithms (tracing)

Consider the following code fragment. X=5 Y=5 WHILE X < 10 X=Y REPEAT add 1 to Y UNTIL Y >= 10 ENDWHILE print X, Y What is the output produced?

  1. 10, 10
  2. 10, 11
  3. 11, 10
  4. 11, 11
Answer

B

NESA answer key: B. Trace: X=5,Y=5. Pass 1: X=Y=5, then REPEAT adds 1 to Y until Y>=10, so Y=10. X is 5 (<10) so pass 2: X=Y=10, REPEAT runs once more (post-test) so Y=11. X is 10, the WHILE ends. Output 10, 11. Old syllabus (SDD): useful as overlap practice only.

2. Algorithms (tracing)

Consider the following algorithm. BEGIN A=3 B=4 C=5 A=B+C B=A C=B D=A+B+C Display D END What output is produced?

  1. 12
  2. 16
  3. 26
  4. 27
Answer

D

NESA answer key: D. A=4+5=9, B=9, C=9, D=27. Old syllabus (SDD): useful as overlap practice only.