Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

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


1 Answer
karthikeya Boyini

This is a C++ program to compute Combinations using Recurrence Relation for nCr.

Algorithms

Begin
   function CalCombination():
      Arguments: n, r.
      Body of the function:
      Calculate combination by using
      the formula: n! / (r! * (n-r)!.
End

Example

#include<iostream>
using namespace std;
float CalCombination(float n, float r) {
   int i;
      if(r > 0)
         return (n/r)*CalCombination(n-1,r-1);
      else
   return 1;
}
int main() {
   float n, r;
   int res;
   cout<<"Enter the value of n: ";
   cin>>n;
   cout<<"Enter the value of r: ";
   cin>>r;
   res = CalCombination(n,r);
   cout<<"\nThe number of possible combinations are: nCr = "<<res;
}

Output

Enter the value of n: 7
Enter the value of r: 6
The number of possible combinations are: nCr = 2

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.