title: Different output for binomial coefficient function C++
body: <p>I use two method to calculate the binomial coefficient.
  one is </p>
  
  <pre><code>int fac(int n) {
  if ( n &lt; 2 ) return 1; // return 1 when n=0,1
  int ret = 1;
  for(int i=2; i &lt;= n; ++i)
      ret *= i;  // calculate factorial
  return ret;
  }
  int choose_fac(int n, int k) {
    return fac(n)/fac(k)/fac(n-k);
  }
  </code></pre>
  
  <p>The other one is:</p>
  
  <pre><code>int choose_dp(int n, int k) {
    int C[n+1][k+1];
    int i, j;
    for (i = 0; i &lt;= n; i++) {
          for (j = 0; j &lt;= min(i, k); j++) {
              if (j == 0 || j == i) C[i][j] = 1;
              else C[i][j] = C[i-1][j-1] + C[i-1][j];
          }
    }
    return C[n][k];
  }
  </code></pre>
  
  <p>So when i run on (15,5), the second one give the right answer while first one gives 4. I know that for choose_fac the int goes out of range when calculate 15!, but if this is the reason, why choose_dp doesn't return a wrong answer as they both use int to define the function?</p>
  
  <p>Thanks a lot!</p>
  
  <p>E.</p>