ProgrammingModerateAccenture · Cognizant GenC Next

What will be the output of the following pseudocode? (All variables are integers, so / is integer division)

What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
Integer n = 77, steps = 0, p
while (n >= 10)
    p = 1
    while (n > 0)
        p = p * (n mod 10)
        n = n / 10
    end while
    n = p
    steps = steps + 1
end while
Print n, steps
  1. A. 8 4
  2. B. 8 3
  3. C. 9 4
  4. D. 6 4

Correct answer: A. 8 4

Multiply the digits repeatedly: 77 → 49 → 36 → 18 → 8. That is 4 steps, ending at 8: 8 4.

More Pseudocode and Code Tracing questions

Exams that ask this topic