ProgrammingVery hardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
unsigned long long g(int n) {
    if (n < 2) return 0;
    return g(n - 1) + g(n - 2) + 1;
}
int main(void) {
    printf("%llu", g(6));
}
  1. A. 12
  2. B. 7
  3. C. 13
  4. D. 11

Correct answer: A. 12

g(n) = g(n - 1) + g(n - 2) + 1 with g(0) = g(1) = 0 gives 0, 0, 1, 2, 4, 7, 12 for n = 0 to 6. The answer is g(6) = 12.

More C Programming questions

Exams that ask this topic