include iostream include cmath using namespace std double average doub

 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
#include <iostream>
#include <cmath>
using namespace std;
double average(double const *arr, size_t dimension) { // среднее значение
double average = 0;
for (int i = 0; i < dimension; ++i) {
average += arr[i];
}
return average / dimension;
}
double dispersion(double const *arr, size_t dimension) { // дисперсия
double dispersion = 0;
double avg = average(arr, dimension);
for (int i = 0; i < dimension; i++) {
dispersion += (arr[i] - avg) * (arr[i] - avg);
}
return dispersion / dimension;
}
double deviation(double const *arr, size_t dimension) { // отклонение
return sqrt(dispersion(arr, dimension));
}
int main() {
size_t dimension;
cout << "Enter dimension of array: " << endl;
cin >> dimension;
double *arr = new double[dimension]; // Выделение памяти для массива
for (int i = 0; i < dimension; ++i) {
cout << "Enter arr[" << i << "]: " << endl;
cin >> arr[i];
}
cout << "Average value: " << average(arr, dimension) << endl;
cout << "Dispersion value: " << dispersion(arr, dimension) << endl;
cout << "Deviation value: " << deviation(arr, dimension) << endl;
delete[] arr;
return 0;
}