ProgrammingModerateWipro NLTH · Cognizant GenC

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer x = 1, i
for (i = 1; i <= 5; i = i + 1)
    x = (x * 3) mod 7
end for
Print x
  1. A. 1
  2. B. 3
  3. C. 5
  4. D. 6

Correct answer: C. 5

x goes 3, 2, 6, 4, 5 (mod 7), so it ends at 5.

More Pseudocode and Code Tracing questions

Exams that ask this topic