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));
}- A. 12586269025
- B. 3996334433
- C. 3996334432
- 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
- What is printed? c #include <stdio.h> void rev(const char s) { if (s == '0') return; rev(s + 1); putchar(s); } int main(void) {…
- What is printed? c #include <stdio.h> int calls = 0; int A(int m, int n) { calls++; if (m == 0) return n + 1; if (n == 0) return A(m - 1…
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0x16D; printf("%u", x & 0xF); }
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned x = 32, b1 = (x >> 1) & 1u, b5 = (x >> 5)…
- What is printed? c #include <stdio.h> int main(void) { unsigned a = 0xC, b = 0xA, c = 0x9; unsigned m = (a & b) | (b & c) | (a & c)…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 4, 6}, b[] = {2, 3, 8, 9}; int m[7], i = 0, j = 0, k = 0; while (i <…