ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
int fib(int n) {
    if (n <= 1) return n;
    return fib(n - 1) + fib(n - 2);
}
int main(void) {
    printf("%d", fib(6));
}
  1. A. 13
  2. B. 5
  3. C. 21
  4. D. 8

Correct answer: D. 8

Standard Fibonacci (0,1,1,2,3,5,8,...): fib(6) is the 7th term (0-indexed), which is 8.

More C Programming questions

Exams that ask this topic