ProgrammingModerateWipro NLTH · Cognizant GenC

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer i, j, c = 0
for (i = 1; i <= 6; i = i + 1)
    for (j = 1; j <= 6; j = j + 1)
        if (i < j)
            c = c + 1
        end if
    end for
end for
Print c
  1. A. 21
  2. B. 30
  3. C. 15
  4. D. 36

Correct answer: C. 15

The pairs with i < j number 5 + 4 + 3 + 2 + 1 = 15.

More Pseudocode and Code Tracing questions

Exams that ask this topic