standard deviation function in c 2b 2b

Solutions on MaxInterview for standard deviation function in c 2b 2b by the best coders in the world

showing results for - "standard deviation function in c 2b 2b"
Brighton
04 Feb 2018
1#include<iostream>
2#include<cmath>
3using namespace std;
4int main(int argc, char const *argv[])
5{
6    double mean;
7    double nums[] = {9, 2, 5, 4, 12, 7, 8, 11, 9, 3, 7, 4, 12, 5, 4, 10, 9, 6, 9, 4};
8    double standardDeviation = 0;
9    double arraySize = *(&nums + 1) - nums;
10
11    for (int i = 0; i < arraySize; i++){ mean = (nums[i] + mean);}
12    mean = mean/ arraySize;
13    for (int i = 0; i < arraySize; i++){
14        standardDeviation += pow((nums[i] - mean), 2);
15    }
16    standardDeviation = sqrt(standardDeviation / arraySize);
17    cout << standardDeviation << endl;
18    return 0;
19}