Pseudo-code · Question 29 · Hard

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

Integer a, b, c, i
Set a = 1, b = 1
for (i = 1 to 6)
    c = (a + b) mod 10
    a = b
    b = c
end for
Print a * b
  1. 104
  2. 3
  3. 24
  4. 273
Answer and explanation

Answer: B. 3

Explanation: These are Fibonacci numbers with only the last digit kept. After the 6 iterations (a, b) goes (1, 2), (2, 3), (3, 5), (5, 8), (8, 3), (3, 1), so a * b = 3 × 1 = 3.

Previous: What will be the output of the following pseudocode? · Next: What will be the output of the following pseudocode? (Note: for-loop bounds…

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