-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPemutationCombination.cpp
More file actions
53 lines (47 loc) · 1.13 KB
/
Copy pathPemutationCombination.cpp
File metadata and controls
53 lines (47 loc) · 1.13 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//WAP to calculate Factorial of a number.
#include <iostream>
using namespace std;
int calFact(int n) //Function to calculate Factorial
{
int fact=1;
for (int i=1;i<=n;i++)
{
fact*=i; //Calculating Factorial
}
return fact;
}
double permutation(int n,int r) //Function to calculate permutaion
{
double permu;
permu=calFact(n)/calFact((n-r)); //Calculating Permutaion
return permu;
}
double combination(int n,int r) //Function to calculate combination
{
double combi;
combi=calFact(n)/(calFact(r)*calFact((n-r))); //Calculating combination
return combi;
}
void input(int& n,int& r) //Taking inputs
{
A: cout<<"Enter value of n"<<endl;
cin>>n;
cout<<"Enter value of r"<<endl;
cin>>r;
if(r>n)
{
cout<<"WRONG INPUT"<<endl;
goto A;
}
}
int main()
{
int n,r;
double permu,combi;
input(n,r); //Calling input()
permu=permutation(n,r); //Calling permutaion()
combi=combination(n,r); //Calling Combination()
cout<<"Permutaion of n,r= "<<permu<<endl;
cout<<"Combination of n,r= "<<combi;
return 1;
}