ProgrammingVery hardTCS NQT · Accenture

Fibonacci numbers are defined by F0 = 0, F1 = 1 and Fn = Fn-1 + Fn-2. The procedure below computes F50 by iteration and then prints F50 mod 10 (the last digit). What is printed?

Fibonacci numbers are defined by F0 = 0, F1 = 1 and Fn = Fn-1 + Fn-2. The procedure below computes F50 by iteration and then prints F50 mod 10 (the last digit). What is printed?
a = 0; b = 1
repeat 50 times: (a, b) = (b, a + b)
Print a mod 10
  1. A. 9
  2. B. 4
  3. C. 12586269025
  4. D. 5

Correct answer: D. 5

F50 = 12586269025, whose last digit is 5. The loop stopping at F49 or F51 gives last digits 9 or 4, and printing the full value without the mod gives 12586269025.

More Pseudocode and Code Tracing questions

Exams that ask this topic