Mar 24, 2021 at 7:07pm UTC
#include <iostream>
#include <cmath>
using namespace std;
float CalstdDeviation(float StoreArr[]);
int main()
{
int i;
float StoreArr[5];
cout << "Enter five(5) elements: ";
for(i = 0; i < 5; ++i)
cin >> StoreArr[i];
cout << endl << "average :" << CalstdDeviation(StoreArr) << endl;
cout << endl <<"The Sample Standard Deviation is = " << CalstdDeviation(StoreArr) << endl;
return 0;
}
float CalstdDeviation(float StoreArr[])
{
float sum = 0.0, mean, average, standardDeviation = 0.0;
int i;
for(i = 0; i < 5; ++i)
sum += StoreArr[i];
mean = sum / 5;
cout << mean << endl;
standardDeviation += pow(StoreArr[i] - mean, 2);
return sqrt(4 - 1 / sum);
return(average = sum / 5);
}
// main
The five numbers entered should be 1, 6, 9, 5, 0. I suppose to have 4.2 as an average and the sample standard deviation is 3.70135. Can some help please?
Currently I am getting the average and the standard deviation twice.