C Programming Code Examples C > Mathematics Code Examples Program to Calculate Standard Deviation Program to Calculate 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 <stdio.h> #include <math.h> float calculateSD(float data[]); int main() { int j; float data[10]; printf("Enter 10 elements: "); for(j=0; j < 10; ++j) scanf("%f", &data[j]); printf("\nStandard Deviation = %.6f", 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); }