forked from v100901/hackoctoberfest2020__
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnCr-nPr.cpp
37 lines (37 loc) · 776 Bytes
/
nCr-nPr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
using namespace std;
int main()
{
long long fact=1, numerator, denominator;
int npr, ncr, n, r, i=1, sub;
cout<<"Enter the Value of n: ";
cin>>n;
cout<<"Enter the Value of r: ";
cin>>r;
while(i<=n)
{
fact = i*fact;
i++;
}
numerator=fact; // fact = n!
sub = n-r;
fact=1, i=1;
while(i<=sub)
{
fact = i*fact;
i++;
}
denominator = fact; // fact = (n-r)!
npr = numerator/denominator;
i=1, fact=1;
while(i<=r)
{
fact = i*fact;
i++;
}
ncr = npr/fact; // fact = r!
cout<<"\nPermutation (nPr) = "<<npr;
cout<<"\nCombination (nCr) = "<<ncr;
cout<<endl;
return 0;
}