Created
October 15, 2015 10:34
-
-
Save recoverlee/83e92c26b8fbf3d61788 to your computer and use it in GitHub Desktop.
combination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// nPr = n! / (n-r)! | |
// nCr = nPr / r! = n! / ((n-r)! * r!) | |
int combination(int n, int r) | |
{ | |
int ret = 1; | |
for (int i = 1; i <= r; i++) | |
{ | |
ret = ret*(n - i + 1) / i; | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment