stddevi

Description:

Calculate Standard Deviation using functions Test Case 1 Input (stdin) 1 2 3 4 5 6 7 8 9 10 Expected Output 2.87228 Test Case 2 Input (stdin) 11 21 13 4 5 6 7 8 9 10 Expected Output 4.67333

Program :

#include <iostream>


#include <cmath>


using namespace std;

 float calculateSD(float data[]);

int main() {

  int i;

  float data[10];

  for(i=0;i<10;++i)

  cin>>data[i];

  float calculatedSD(float data[]);

  cout<<calculatedSD(data);

  return 0;

}

float calculatedSD(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 );

}