ProgrammingVery hardGATE CS · Competitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int C(int n) {
    if (n == 0) return 1;
    int s = 0;
    for (int i = 0; i < n; i++)
        s += C(i) * C(n - 1 - i);
    return s;
}
int main(void) {
    printf("%d", C(4));
}
  1. A. 10
  2. B. 12
  3. C. 14
  4. D. 16

Correct answer: C. 14

This recursion computes the Catalan numbers, which count binary trees with n nodes. C(4) = 14.

More C Programming questions

Exams that ask this topic