-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatihanets.cpp
73 lines (69 loc) · 1.88 KB
/
latihanets.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i, j, n, max;
int desired;
max = 1;
n = 5;
// float X[n];
float X[n] = {12, 12, 13, 14, 27};
cout << "Pengurutan : " << endl;
cout << "1. Lowest" << endl;
cout << "2. Highest" << endl;
cout << "Masukkan pilihan : ";
cin >> desired;
for (i = 0; i < n; i++)
{
// cout << "Masukkan Array ke-"
// << " ";
// cin >> X[i];
for (j = 0; j < n; j++)
{
switch (desired)
{
case 1:
if (X[j] > X[i])
{
max = X[i];
X[i] = X[j];
X[j] = max;
}
break;
case 2:
if (X[j] > X[i])
{
max = X[j];
X[j] = X[i];
X[i] = max;
}
default:
break;
}
}
}
// cout << X[0];
cout << "{";
for (j = 0; j < n; j++)
{
cout << " " << X[j] << " ";
}
cout << "}" << endl;
cout << "Dengan Median : ";
if (n % 2 == 0)
{
cout << (X[(n / 2 - 1)] + X[(n / 2)]) / 2 << endl;
cout << "Quartil 1 " << fixed << setprecision(2) << X[((n + 2) / 4) - 1] << endl;
cout << "Quartil 2 " << fixed << setprecision(2) << (X[n / 2 - 1] + X[n / 2]) / 2 << endl;
cout << "Quartil 3 " << fixed << setprecision(2) << X[((3 * (n + 2)) / 4) - 2] << endl;
}
else
{
cout << X[(n - 1) / 2] << endl;
cout << "Quartil 1 " << fixed << setprecision(2) << X[((n + 1) / 4) - 1] << endl;
cout << "Quartil 2 " << fixed << setprecision(2) << (X[(n - 1) / 2]) << endl;
cout << "Quartil 3 " << fixed << setprecision(2) << X[((3 * (n + 1)) / 4) - 1] << endl;
}
return 0;
}