ProgrammingModerateAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a = 10, b = 20, c = 30, r
if (a > b AND b > c)
    r = 1
else if (a < b OR c < b)
    r = 2
else
    r = 3
end if
a = a + b
b = a - b
c = c - a
Print r, a, b, c
  1. A. 2 30 20 0
  2. B. 2 30 10 0
  3. C. 3 30 10 0
  4. D. 2 30 10 -30

Correct answer: B. 2 30 10 0

a < b is true, so r = 2. Then a = 30, b = 30 − 20 = 10 (the old a), c = 30 − 30 = 0, because c uses the updated a.

More Pseudocode and Code Tracing questions

Exams that ask this topic