Pseudo-code · Question 21 · Medium

What will be the output of the following pseudocode? (Note: for-loop bounds are inclusive.)

Integer i, j, c
Set c = 0
for (i = 1 to 5)
    for (j = 1 to 5)
        if ((i + j) mod 3 == 0)
            c = c + 1
        end if
    end for
end for
Print c
  1. 7
  2. 8
  3. 9
  4. 10
Answer and explanation

Answer: C. 9

Explanation: c counts pairs (i, j) from 1 to 5 whose sum is a multiple of 3. Sum 3 has 2 pairs, sum 6 has 5 pairs and sum 9 has 2 pairs, so c = 9.

Previous: What will be the output of the following pseudocode? (Note: / denotes integer… · Next: What will be the output of the following pseudocode?

Practise pseudo-code

Try a fresh set of pseudo-code questions with an explanation after every answer, free and without signing up: Pseudo-code practice. Or sit a full placement mock test.

More pseudo-code questions

More technical & programming practice

C Programming · Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge