ProgrammingHardCapgemini · C
What is printed?
What is printed?
int f(int n) { return n <= 1 ? 1 : f(n - 1) + f(n - 2) + n; }
int main(void) {
printf("%d", f(5));
return 0;
}- A. 8
- B. 29
- C. 16
- D. 24
Correct answer: B. 29
f(0) = f(1) = 1; f(2) = 4, f(3) = 8, f(4) = 16, f(5) = 16 + 8 + 5 = 29.
More C Programming questions
- What is printed? c void g(int a[]) { printf("%d ", (int)(sizeof(a) == sizeof(int ))); } int main(void) { int a[10]; g(a); printf("%zu"…
- What is printed? c char s[20] = "abc"; strcat(s, "de"); strncpy(s + 1, "XYZW", 2); printf("%s %zu", s, strlen(s));
- What is printed? c int n = printf("ab%d", 123); printf(" %d", n);
- What is printed? c enum { A, B = 5, C, D = C + 2, E }; printf("%d %d %d", C, D, E);
- What is printed? c unsigned int x = 0xB4; printf("%u %u", x & -x, x & (x - 1));
- What is printed? Assume a C compiler where double is larger than float. c printf("%d %d %d", sizeof('a') == sizeof(int), sizeof(1.5f) ==…