Wednesday 22 November 2017

C++ Program to Compute Combinations using Recurrence Relation for nCr


Code:

#include    iostream

using namespace std;

// A function to calculate combination using recurrence relation.
float CalcCombination(float n, float r)
{
int i, res;
if(r > 0)
return (n/r)*CalcCombination(n-1,r-1);
else 
return 1;
}

int main()
{
float n, r;
int result;
cout<<"A program to find combination from nCr format";
cout<<"\n\n\tEnter the value of n: ";
cin>>n;
cout<<"\tEnter the value of r: ";
cin>>r;

// Get result using recurrence relation.
result = CalcCombination(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:















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...