C program to Calculate Standard Deviation
ADVERTISEMENTS
C program to calculate standard deviation.
In this article, you will learn how to calculate the standard deviation of the input numbers.
Example
TTell me count of numbers to calculate the standard deviation: 5
Enter the 5 elements:
10
30
50
70
90
Standard Deviation = 32.015621
Source
// C program to calculate Standard Deviation
#include <stdio.h>
#include <math.h>
// It's main function of the program
int main() {
int sd_count, i;
float sum = 0.0, mean, sd_val = 0.0;
printf("Tell me count of numbers to calculate the standard deviation: ");
scanf("%d", &sd_count);
float sd_elements[sd_count];
printf("\nEnter the %d elements:\n", sd_count);
for (i = 0; i < sd_count; i++) {
scanf("%f", &sd_elements[i]);
sum += sd_elements[i];
}
mean = sum / 10;
for (i = 0; i < 10; i++) {
sd_val += pow(sd_elements[i] - mean, 2);
}
// Final output of the program
printf("\nStandard Deviation = %.6f\n", sqrt(sd_val / 10));
return 0;
}
Output
Tell me count of numbers to calculate the standard deviation: 5
Enter the 5 elements:
10
30
50
70
90
Standard Deviation = 32.015621