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?
- A. 12586269025
- B. 3996334433
- C. 4294967295
- 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
- int x = 5; x = x++; What is the outcome of this statement?
- uint16t h = 0; for each character c of "ABCDE", h = h 31 + c; with 65 for 'A' and so on. What is h at the end?
- Which function correctly tests whether an unsigned value x is a power of two, with x = 0 excluded?
- char b[6]; snprintf(b, sizeof b, "%s-%d", "abcdef", 12345); int r = snprintf(NULL, 0, "%s-%d", "abcdef", 12345); printf("%s %d", b, r)…
- char b[5]; / stdin holds the nine bytes: abcdefgh and a newline / int calls = 0; do { fgets(b, sizeof b, stdin); calls++; } while…
- char s[] = "a,,b,c"; int n = 0; for (char t = strtok(s, ","); t != NULL; t = strtok(NULL, ",")) n++; printf("%d", n); What is printed?