ProgrammingHardWipro 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 (j > i)
            break
        end if
        if ((i + j) mod 2 == 1)
            continue
        end if
        c = c + 1
    end for
end for
Print c
  1. A. 21
  2. B. 9
  3. C. 11
  4. D. 12

Correct answer: D. 12

For each i, j runs from 1 to i; counting j with the same parity as i gives 1, 1, 2, 2, 3, 3 = 12.

More Pseudocode and Code Tracing questions

Exams that ask this topic