-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathfatik07_permutasi.cpp
More file actions
49 lines (38 loc) · 1014 Bytes
/
fatik07_permutasi.cpp
File metadata and controls
49 lines (38 loc) · 1014 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
#include <iostream>
using namespace std;
void permutasi()
{
int n,r;
int nfak=1, nrfak=1;
cout<<"MENCARI PERMUTASI"<<endl;
cout<<"----------------------------------"<<endl;
cout<<"Masukkan n : ";
cin>>n;
cout<<"Masukkan r : ";
cin>>r;
//r tidak boleh lebih besar dari n unsur
while (n<r){
cout<<"\nr tidak boleh lebih besar dari n";
cout<<"\nMasukkan n : ";
cin>>n;
cout<<"Masukkan r : ";
cin>>r;
}
// perulangan permutasi
for(int i=n; i>0; i--){ //perulangan n faktorial
nfak = nfak * i;
}
for(int i=n-r; i>0; i--){ //perulangan n-r faktorial
nrfak = nrfak * i;
}
cout << "\nNilai dari n adalah " << nfak;
cout << "\nNilai dari r adalah " << nrfak;
//rumus permutasi
cout<< "\nHasil dari permutasi tersebut dari " << nfak << " / " << nrfak << " adalah : " << nfak/nrfak;
cout << "\n\n";
}
int main()
{
permutasi();
return 0;
}