NCR
This algorithm finds all the possible combination of the value n and r.
/*****Please include following header files*****/
// stdint.h
/***********************************************/
int64_t Factorial(int number) {
if (number < 0)
return -1; //Error
int64_t result = 1;
for (int i = 1; i <= number; ++i)
result *= i;
return result;
}
int64_t NCR(int n, int r) {
return Factorial(n) / (Factorial(r) * Factorial(n - r));
}
Example
int64_t ncr = NCR(5, 2);
Output
10