C++ Programming Code Examples C++ > Mathematics Code Examples Program to Calculate Standard Deviation Program to Calculate Standard Deviation This program calculates the standard deviation of 10 data using arrays. This program calculates the standard deviation of a individual series using arrays. Visit this page to learn about Standard Deviation. To calculate the standard deviation, calculateSD() function is created. The array containing 10 elements is passed to the function and this function calculates the standard deviation and returns it to the main() function. #include <iostream> #include <cmath> using namespace std; float calculateSD(float data[]); int main() { int j; float data[10]; cout << "Enter 10 elements: "; for(j = 0; j < 10; ++j) cin >> data[j]; cout << endl << "Standard Deviation = " << calculateSD(data); return 0; } float calculateSD(float data[]) { float sum = 0.0, mean, standardDeviation = 0.0; int j; for(j = 0; j < 10; ++j) { sum += data[j]; } mean = sum/10; for(j = 0; j < 10; ++j) standardDeviation += pow(data[j] - mean, 2); return sqrt(standardDeviation / 10); }