title: Calculate the nth Catalan number
body: <p>I wrote some code to calculate the Nth catalan number. However, it isn't returning the correct result when N=20 and onwards. The results when N&lt;20 is correct though, so I'm not sure what is wrong. </p>
  
  <p>So, when N=20, its supposed to return 6564120420, but it returns 2269153124 for me.</p>
  
  <p>Can someone point me in the right direction?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  unsigned long int countTree(unsigned int N)
  {
      //used to store catalan numbers
      unsigned long int catalan[N+1];
  
      //N(0)=N(1)=1
      catalan[0]=catalan[1]=1;    
      int i,j;
  
      for(i=2;i&lt;=N;i++)
      {
          catalan[i]=0;
          for(j=0;j&lt;i;j++)
          {
              catalan[i]+=catalan[j]*catalan[i-j-1];
          }
      }
      return catalan[N];
  }
  
  int main()
  {
      unsigned int x;
      cout&lt;&lt;"Input N:"&lt;&lt;endl;
      cin&gt;&gt;x;
      unsigned long int result=countTree(x);
      cout&lt;&lt;result&lt;&lt;endl;
      return 0;
  }
  </code></pre>