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




:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
cheer

FIND US ON FACEBOOK!