NCR

This algorithm finds all the possible combination of the value n and r.



									private static long Factorial(int number)
{
	if (number < 0)
		return -1; //Error

	long result = 1;

	for (int i = 1; i <= number; ++i)
		result *= i;

	return result;
}

public static long NCR(int n, int r)
{
	return Factorial(n) / (Factorial(r) * Factorial(n - r));
}
								


Example

									long ncr = NCR(5, 2);
								


Output

									10