-
Notifications
You must be signed in to change notification settings - Fork 0
/
latihanets3.cpp
49 lines (44 loc) · 1.05 KB
/
latihanets3.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
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double sum, mean, pembilang, stdev;
double array[] = {12, 32, 54, 23, 34};
int i, data, n = sizeof(array) / sizeof(array[0]);
cout << "Masukkan opsi : " << endl;
cout << "1. Data Sampel" << endl;
cout << "2. Data Populasi" << endl;
cin >> data;
sum = 0, pembilang = 0;
switch (data)
{
case 2:
for (i = 0; i < n; i++)
{
sum = sum + array[i];
}
mean = sum / n;
for (i = 0; i < n; i++)
{
pembilang = pembilang + ((array[i] - mean) * (array[i] - mean));
}
stdev = sqrt(pembilang / n);
break;
case 1:
for (i = 0; i < n; i++)
{
sum = sum + array[i];
}
mean = sum / (n - 1);
for (i = 0; i < n; i++)
{
pembilang = pembilang + ((array[i] - mean) * (array[i] - mean));
}
stdev = sqrt(pembilang / (n - 1));
default:
break;
}
cout << stdev;
return 0;
}