Answers for "standard deviation function in c++"

C++
1

standard deviation function in c++

#include<iostream>
#include<cmath>
using namespace std;
int main(int argc, char const *argv[])
{
    double mean;
    double nums[] = {9, 2, 5, 4, 12, 7, 8, 11, 9, 3, 7, 4, 12, 5, 4, 10, 9, 6, 9, 4};
    double standardDeviation = 0;
    double arraySize = *(&nums + 1) - nums;

    for (int i = 0; i < arraySize; i++){ mean = (nums[i] + mean);}
    mean = mean/ arraySize;
    for (int i = 0; i < arraySize; i++){
        standardDeviation += pow((nums[i] - mean), 2);
    }
    standardDeviation = sqrt(standardDeviation / arraySize);
    cout << standardDeviation << endl;
    return 0;
}
Posted by: Guest on February-04-2021

Code answers related to "standard deviation function in c++"

Browse Popular Code Answers by Language