Standard Deviation

This algorithm calculates the standard deviation of the given set of numbers.



									/*****Please include following header files*****/
// vector
// cmath
/***********************************************/

/*****Please use following namespaces*****/
// std
/*****************************************/

double StandardDeviation(vector<double> data)
{
	double mean = 0.0;
	double sumDeviation = 0.0;
	int dataSize = data.size();

	for (int i = 0; i < dataSize; ++i)
		mean += data[i];

	mean = mean / dataSize;

	for (int i = 0; i < dataSize; ++i)
		sumDeviation += (data[i] - mean) * (data[i] - mean);

	return sqrt(sumDeviation / dataSize);
}
								


Example

									vector<double> data = { 13, 23, 12, 44, 55 };
double standardDeviation = StandardDeviation(data);
								


Output

									17.211623979160130