The code is running fine, but the problem is that we ahve declared array cn of size n, so consifering 0 index, it should run till n-1. But it is working for. how can this happen. And the answer should be cn[n-1] not cn[n].
#include
using namespace std;
int main() {
int n;
cin>>n;
long long cn[n];
cn[0] = cn[1] = 1;
for(int i = 2; i<=n; i++){
cn[i] = 0;
for(int j = 0; j<i; j++){
cn[i] += cn[j]*cn[i-j-1];
}
}
cout<<cn[n]<<endl;;
return 0;
}