C++ Program to calculate Permutation and Combination [DEVCPP/GCC]

PERMUTATION

Formula to find number of different permutations of n distinct objects taken r at a time is  

COMBINATION

Formula to find number of different combinations of n distinct objects taken r at a time is
PROGRAM

//Program to calculate Permutation and Combination

#include<iostream>

using namespace std;

int fact(int num) 
{
         if(num==1) 
        {
              return 1;
        }
        else 
        {
             return num * fact(num-1);
        }
}

int main() 
{
       int n,r,nPr,nCr;

       cout<<"Enter n: ";
       cin>>n;
       
       cout<<"Enter r: ";
       cin>>r;

       nPr=fact(n)/fact(n-r);

       nCr=nPr/fact(r);

       cout<<"nPr is: "<<nPr<<endl;
       cout<<"nCr is: "<<nCr;

       return 0;
}

OUTPUT




FIND US ON FACEBOOK!