[ create a new paste ] login | about

Link: http://codepad.org/G8LDY47D    [ raw code | output | fork ]

C, pasted on Dec 6:
#if 0
nCm = n-1Cm + n-1Cm-1
#endif

#include <stdio.h>

int combination(int n, int m)
{
  if (m == 0)
    return 1;
  if (n == m)
    return 1;
  return combination(n - 1, m) + combination(n - 1, m - 1);
}

int main()
{
  int a, b;
  printf("> ");
  if (scanf("%d %d", &a, &b) == 2) {
    printf("%dC%d = %d\n", a, b, combination(a, b));
  }
  return 0;
}
/* end */


Output:
1
> 


Create a new paste based on this one


Comments: