-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram3.cpp
More file actions
49 lines (40 loc) · 976 Bytes
/
program3.cpp
File metadata and controls
49 lines (40 loc) · 976 Bytes
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
// program to find the permutation and combination
#include<iostream>
using namespace std;
int fact(int a){
if (a>1){
return a * fact(a-1);
}
else{
return 1;
}
}
int main(){
int n,r,choice,n1,n2,n3;
cout<<"Enter the value of n and r respectively : ";
abc:
cin>>n>>r;
if (n<r){
cout<<"n should be greater than or equal to r ,write it again "<<endl;
goto abc;
}
cout<<"1. Permutation \n2. Combination\nEnter your choice : ";
cin>>choice;
switch(choice){
case 1:
n1 = fact(n);
n2 = fact(n-r);
n3 = n1/n2;
cout<<"Permutation is "<<n3<<endl;
break;
case 2:
n1 = fact(n);
n2 = fact(n-r)*fact(r);
n3 = n1/n2;
cout<<"combination is "<<n3<<endl;
break;
default:
cout<<"Invalid Choice"<<endl;
}
return 0;
}