Pseudo-code · Question 14 · Hard

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

Integer x, y, i
Set x = 3, y = 5
for (i = 1 to 4)
    x = (x + y) mod 7
    y = (x * i) mod 5
end for
Print x + y
  1. 7
  2. 6
  3. 5
  4. 4
Answer and explanation

Answer: C. 5

Explanation: Tracing (x, y): i = 1 gives (1, 1); i = 2 gives (2, 4); i = 3 gives (6, 3); i = 4 gives (9 mod 7 = 2, 8 mod 5 = 3). x + y = 2 + 3 = 5.

Previous: What will be the output of the following pseudocode? (Note: &, | and ^ are… · Next: What will be the output of the following pseudocode? (Note: array indices…

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