Code:
#include iostream
using namespace std;
// A function to find the factorial.
int factorial(int n)
{
int i;
for(i = n-1; i > 1; i--)
n *= i;
return n;
}
int main()
{
int n, r, result;
cout<<"A program to find combination from nCr format using ( n! / (r! * (n-r)!))";
cout<<"\n\n\tEnter the value of n: ";
cin>>n;
cout<<"\tEnter the value of r: ";
cin>>r;
// Get result using formula to calculate combinations.
result = factorial(n)/(factorial(r)*factorial(n-r));
cout<<"\nThe number of possible combinations is: "<
}
Output:
Case 1:
A program to find combination from nCr format using ( n! / (r! * (n-r)!))
Enter the value of n: 5
Enter the value of r: 3
The number of possible combinations is: 10
Case 2:
A program to find combination from nCr format using ( n! / (r! * (n-r)!))
Enter the value of n: 13
Enter the value of r: 4
The number of possible combinations is: 221
More C++ Programs: