ProgrammingEasyTCS NQT · Accenture pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer n = 5, f = 1
while (n > 1)
    f = f * n
    n = n - 1
end while
Print f
  1. A. 60
  2. B. 24
  3. C. 720
  4. D. 120

Correct answer: D. 120

f = 5 × 4 × 3 × 2 = 120. The loop stops when n reaches 1, which makes no difference because multiplying by 1 changes nothing.

More Pseudocode and Code Tracing questions

Exams that ask this topic