ProgrammingHardTCS NQT · Accenture pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a = 1, b = 2, c = 3
a = (a < b) ? b : c
b = (b < c AND a == 2) ? c : a
c = (a > b OR c > a) ? a + b : 0
Print a, b, c
  1. A. 2 3 5
  2. B. 2 2 4
  3. C. 3 3 6
  4. D. 2 3 0

Correct answer: A. 2 3 5

a < b, so a = 2. Then b < c and a == 2, so b = c = 3. Finally a > b is false but c (3) > a (2) is true, so c = a + b = 5. Each line uses the values updated by the previous lines.

More Pseudocode and Code Tracing questions

Exams that ask this topic