Calculate Standard Deviation

    0

    0

    Giovanny Gongora

    Codiga's C++ Recipes

    Calculates the standard deviation of an individual series using arrays.

    #include <iostream>
    #include <cmath>
    
    using namespace std;
    float calculateSD(float data[]);
    float calculateSD(float data[]) {
      float sum = 0.0, mean, standardDeviation = 0.0;
      int i;
      for(i = 0; i < 10; ++i) {
        sum += data[i];
      }
      mean = sum / 10;
      for(i = 0; i < 10; ++i) {
        standardDeviation += pow(data[i] - mean, 2);
      }
      return sqrt(standardDeviation / 10);
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.