-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrayquartil.cpp
62 lines (50 loc) · 1.42 KB
/
arrayquartil.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
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int max, n, j, i;
cout << "Masukkan ukuran array : ";
cin >> n;
float X[n];
for (j = 0; j < n; j++)
{
cout << "Masukkan data array ke-" << j << " : ";
cin >> X[j];
}
for (j = 0; j < n; j++)
{
for (i = 0; i < n; i++)
{
if (X[i] > X[j])
{
max = X[i];
X[i] = X[j];
X[j] = max;
}
}
}
cout << "Urutan array dari yang terbesar adalah :\n"
<< " {";
for (i = 0; i < n; i++)
{
cout << X[i] << ", ";
}
cout << "}";
cout << "\nDengan median adalah : ";
if (n % 2 == !0)
{
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;
}
else
{
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;
}
return 0;
}