Created
April 23, 2022 15:54
-
-
Save CodeMaster7000/c372cb762be5fcccfef38c970df09aae to your computer and use it in GitHub Desktop.
A program which calculates the standard deviation of an individual series using an array of 10 numbers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <math.h> | |
| #include <stdio.h> | |
| float calculateSD(float data[]); | |
| int main() { | |
| int i; | |
| float data[10]; | |
| printf("Enter 10 elements:"); | |
| printf("\n"); | |
| for (i = 0; i < 10; ++i) | |
| scanf("%f", &data[i]); | |
| printf("\nStandard Deviation = %.6f", calculateSD(data)); | |
| return 0; | |
| } | |
| float calculateSD(float data[]) { | |
| float sum = 0.0, mean, SD = 0.0; | |
| int i; | |
| for (i = 0; i < 10; ++i) { | |
| sum += data[i]; | |
| } | |
| mean = sum / 10; | |
| for (i = 0; i < 10; ++i) { | |
| SD += pow(data[i] - mean, 2); | |
| } | |
| return sqrt(SD / 10); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment