#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
usingnamespace std;
int factorial(int num)
{
int n = 1;
if (num<0)
{
cerr<<"Error, no factorial for a negative number.\n";
return 0;
}
while (num>0)
{
n *= num;
num--;
}
return n;
}
int main(int nNumberofArgs, char* pszArgs[])
{
cout<<"This program finds 10C5, 100C10 and 40C30.\n";
int combination;
int n1 = 10; int r1 = 5; int n2 = 100;
int r2 = 10; int n3 = 40; int r3 = 30;
//nCr = n!/(r!(n-r)!)
combination = factorial(n1)/((factorial(r1))*factorial(n1-r1));
cout<<"10C5 = "<<combination<<endl;
combination = factorial(n2)/((factorial(r2))*factorial(n2-r2));
cout<<"100C10 = "<<combination<<endl;
combination = factorial(n3)/((factorial(r3))*factorial(n3-r3));
cout<<"40C30 = "<<combination<<endl;
//wait for the user to be ready before terminating the program
cin.get();
return 0;
}