User:Shyal-b/Sandbox/combinations
From Wikipedia, the free encyclopedia
< User:Shyal-b | Sandbox
#include <iostream> #include <vector>
using namespace std;
double factorial(int a) { double r = a; if (a > 0) { while (--a) { r *= a; } } else { r = 1; } return r; }
int combinations(int n, int r) { return((int)(factorial(n)/(factorial(n-r)*factorial(r)))); }
int main() { int n, r;
cout << "Enter any n and r to compute its combinations" << endl;
cout << "n : "; cin >> n; cout << "r : "; cin >> r;
long p = combinations(n, r);
cout << "combinations : " << p << endl;
return 0; }

