Sail E0 Webinar
Question
What is the output of the following code?#includeint cat_number(int n){     int i,j,arr[n],k;     arr[0] = 1;     for(i = 1; i < n; i++)     {         arr[i] = 0;         for(j = 0,k = i - 1; j < i; j++,k--)         arr[i] += arr[j] * arr[k];     }     return arr[n-1];}int main(){     int ans, n = 8;     ans = cat_number(n);     printf("%d\n",ans);     return 0;}
Options:
A .  42
B .  132
C .  429
D .  1430
Answer: Option C


The program prints the 8th Catalan number, which is 429.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

More Questions on This Topic :


Latest Videos

Latest Test Papers