C/C++

Помогите решить задачу, c++, функции

Даны два массива x(n) и Y(m). С использованием функции вычислить среднеквадратичное отклонение элементов в каждом массиве.
Иван Седов
Иван Седов
110
 #include  
#include
#include
#include
#include
using namespace std;
double deviation(vector array)
{ int i, n = array.size();
double s = 0., average = s;
for (i = 0; i < n; i++)
average+= array[i];
average /= n;
for (i = 0; i < n; i++)
s += pow(array[i] - average, 2);
return sqrt(s / n); }
int main()
{ double a, b, c, d; int i, m, n;
cout > a >> b >> c >> d >> m >> n;
vector X(n);
vector Y(m); srand(time(nullptr));
for (i = 0; i < n; i++)
X[i] = a + (b - a) * rand() / RAND_MAX;
for (i = 0; i < m; i++)
Y[i] = c + (d - c) * rand() / RAND_MAX;
cout
Алексей Тихонов
Алексей Тихонов
66 572
Лучший ответ
 #include  
#include
#include
#include
#include
#include

using namespace std;
using array_t = unique_ptr;

size_t input(const char* msg) {
size_t value = 0;
while (!value) {
cout > value;
cin.ignore(0x1000, '\n');
}
return value;
}

void random_fill(array_t& box, size_t n) {
static const auto ten = 10.0;
static uniform_int_distribution uid(100, 999);
static mt19937 gen{ random_device()() };
for (size_t i = 0; i < n; ++i) box[i] = uid(gen) / ten;
}

array_t create(const size_t n) {
array_t box(new double[n]);
if (box != nullptr) random_fill(box, n);
return box;
}

void show(const array_t& box, const size_t n, const streamsize w) {
for (size_t i = 0; i < n; ++i) cout
Берик Билалов
Берик Билалов
63 344