We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f7fd2bc commit 8e0a67eCopy full SHA for 8e0a67e
standard_deviation.cpp
@@ -0,0 +1,36 @@
1
+#include <iostream>
2
+#include <cmath>
3
+using namespace std;
4
+
5
+float calculateSD(float data[]);
6
7
+int main() {
8
+ int i;
9
+ float data[10];
10
11
+ cout << "Enter 10 elements: ";
12
+ for(i = 0; i < 10; ++i) {
13
+ cin >> data[i];
14
+ }
15
16
+ cout << endl << "Standard Deviation = " << calculateSD(data);
17
18
+ return 0;
19
+}
20
21
+float calculateSD(float data[]) {
22
+ float sum = 0.0, mean, standardDeviation = 0.0;
23
24
25
26
+ sum += data[i];
27
28
29
+ mean = sum / 10;
30
31
32
+ standardDeviation += pow(data[i] - mean, 2);
33
34
35
+ return sqrt(standardDeviation / 10);
36
0 commit comments