Why is my output wrong?

I'm trying to write a program that shows the output of the summation formula from k=0 to n C_(n+1)= ∑ C_(k)*C_(n-k).
Here's my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <math.h>

using namespace std;

int main(){

int n;
cout << "Enter n " << endl;
cin  >> n;

int C[n];

C[0] = 1;
C[1] = 1;

cout << C[0] << " ";
cout << C[1] << " ";

for (int i = 2; i < n; i++){
   C[0] = 1;
   C[1] = 1;
   int sum = C[i];
   for (int j = 0; j < i; j++){
      for (int k = n-1; k >= 0; k--){
         sum += (C[j]) * (C[k]);
         cout << C[i] << " ";
      }
   }
}

return 0;
}


My output is:
1 1 5 5 5 5 5 5 5 5 5 5 19463932 
19463932 19463932 19463932 19463932 19463932 
19463932 19463932 19463932 19463932 19463932 
19463932 19463932 19463932 19463932 2686672 
2686672 2686672 2686672 2686672 2686672 2686672 
2686672 2686672 2686672 2686672 2686672 2686672 
2686672 2686672 2686672 2686672 2686672 2686672 
2686672
You have only initialized the two first elements in the array.
Topic archived. No new replies allowed.