ProgrammingVery hardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
unsigned fib(unsigned n) {
    unsigned a = 0, b = 1;
    for (unsigned i = 0; i < n; i++) {
        unsigned t = a + b;
        a = b;
        b = t;
    }
    return a;
}
int main(void) {
    printf("%u", fib(50));
}
  1. A. 12586269025
  2. B. 3996334433
  3. C. 3996334432
  4. D. 2147483647

Correct answer: B. 3996334433

fib(50) = 12586269025, and unsigned addition keeps every step modulo 2^32. Reducing 12586269025 modulo 4294967296 gives 3996334433.

More C Programming questions

Exams that ask this topic