ProgrammingVery hardGATE CS · Campus placements

uint32_t fib(int n) iteratively computes a = 0, b = 1, then n times: t = a + b; a = b; b = t, with all arithmetic in uint32_t. What is fib(50) returned, modulo 2^32?

  1. A. 12586269025
  2. B. 3996334433
  3. C. 4294967295
  4. D. 1

Correct answer: B. 3996334433

The true fib(50) is 12586269025. Reducing it modulo 2^32 gives 12586269025 - 2 * 4294967296 = 3996334433, which is what the uint32_t arithmetic returns.

More C Programming questions

Exams that ask this topic