I am trying to insert all Catalan number in array, but my code is not working.
- Description: Insert the elements in the Catalan sequence in the array given initialized only for C[0].
- Inputs: address of array
- n: next position to be filled;
- top: maximum number of entries to be computed.
- Output:
- int: number of elements in the array.
- Side effects: update the elements of the array.
Code:
#include <stdio.h>
#define MAX 6
int CatSeq (int CatArray[], int n, int top){
int c;
if (top == 1) CatArray[n]= 1;
else{
for ( c = 0; c <= MAX; c++){
CatArray[n] = 2 * (2*top - 1) * CatSeq(CatArray, n, top-1) / (top+1);
n++;
}
}
return n;
}
void PrintSeq(int Seq[], int top){
int i;
for ( i = 1; i < MAX; i++)
printf("%d \n", Seq[i]);
}
int main(){
int c = 0, n = 0 ;
int CatArray[MAX];
c = CatSeq(CatArray, n, MAX);
PrintSeq(CatArray, c);
return 0;
}