#include "stdafx.h" #include <algorithm> #include <numeric> #include <vector> #include <functional> #include <math.h> /* Мне нужно найти среднее квадратное отклонение для массива чисел (например {1,3,5,7,9,11 } -6 цифр + обязательно использовать вот эти 4 функции.. double SredArif(double i[], int num) double SredArif(int i[], int num) double Otklonenie(double i[], int num) double Otklonenie(int i[], int num) */ double SredArif(double i[], int num) { return (std::accumulate(i, i+num, 0.0l) / static_cast<double>(num)); } double Otklonenie(double i[], int num) { typedef double value_type; value_type mod = SredArif(i, num); struct Op : public std::binary_function<value_type, value_type, value_type> { Op(const result_type& mod) : mod_(mod) {} result_type operator() (const first_argument_type& v, const second_argument_type& f) { result_type s = mod_ - f; return v + (s * s); } result_type mod_; }; value_type disp = std::sqrt(std::accumulate(i, i+num, value_type(0), Op(mod)) / static_cast<value_type>(num)); return (disp); } |