ProgrammingEasyAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer p = 2, q = 3
for (each i from 1 to 3)
    p = p * q
    q = q - 1
end for
Print p + q
  1. A. 15
  2. B. 12
  3. C. 13
  4. D. 36

Correct answer: B. 12

i = 1: p = 6, q = 2. i = 2: p = 12, q = 1. i = 3: p = 12 × 1 = 12, q = 0. So p + q = 12. Stopping one pass early gives 13.

More Pseudocode and Code Tracing questions

Exams that ask this topic