<\/span><\/h2>\n\n\n\nIn this challenge, we practice calculating standard deviation<\/em>.<\/p>\n\n\n\n<\/span>Task<\/strong><\/span><\/h2>\n\n\n\nGiven an array, arr<\/em><\/strong>, of n<\/em><\/strong> integers, calculate and print the standard deviation. Your answer should be in decimal form, rounded to a scale of 1<\/strong> decimal place (i.e., 12.3<\/strong> format). An error margin of +0.1<\/strong> will be tolerated for the standard deviation.<\/p>\n\n\n\nExample<\/strong><\/p>\n\n\n\narr<\/em> = [2, 5, 2, 7, 4]<\/strong>
The sum of the array values is 20<\/strong> and there are 5<\/strong> elements. The mean is 4.0<\/strong>.
Subtract the mean from each element, square each result, and take their sum.<\/p>\n\n\n\nTheir sum is 18. Take the square root of 18\/5<\/strong> to get 1.7<\/strong>, the standard deviation.<\/p>\n\n\n\nFunction Description<\/strong><\/p>\n\n\n\nComplete the stdDev<\/em> function in the editor below.<\/p>\n\n\n\nstdDev<\/em> has the following parameters:
– int arr[n]:<\/em> an array of integers<\/p>\n\n\n\nPrints<\/strong>
– float:<\/em> the standard deviation to 1 place after the decimal<\/p>\n\n\n\n<\/span>Input Format<\/strong><\/span><\/h2>\n\n\n\nThe first line contains an integer, n<\/em><\/strong>, denoting the size of arr.
The second line contains n<\/em><\/strong> space-separated integers that describe arr<\/strong><\/em>.<\/p>\n\n\n\n<\/span>Constraints<\/strong><\/span><\/h2>\n\n\n\n- 5 <= n<\/em> <= 100<\/strong><\/li>
- 0 < arr<\/em>[i<\/em>] <= 105<\/sup><\/strong><\/li><\/ul>\n\n\n\n
<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nPrint the standard deviation<\/em> on a new line, rounded to a scale of 1<\/strong> decimal place (i.e., 12.3<\/strong> format).<\/p>\n\n\n\nSample Input<\/strong><\/p>\n\n\n\nSTDIN Function\n----- --------\n5 arr[] size n = 5\n10 40 30 50 20 arr =[10, 40, 30, 50, 20]<\/code><\/pre>\n\n\n\nSample Output<\/strong><\/p>\n\n\n\n14.1<\/code><\/pre>\n\n\n\n<\/span>Solution – Day 1: Standard Deviation Solution<\/strong><\/span><\/h2>\n\n\n\n<\/span>C++<\/strong><\/span><\/h3>\n\n\n\n#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() \n{\n \/* Enter your code here. Read input from STDIN. Print output to STDOUT *\/ \n\n int n; cin>>n; int a[n+4]; double sum=0, sum1=0;\n\n for(auto i=0; i<n; i++)\n {\n cin>>a[i];\n sum += a[i];\n }\n\n double mean = (double)(sum\/n);\n\n for(auto i=0; i<n; i++)\n {\n sum1 += (((double)a[i]-mean)*((double)a[i]-mean));\n }\n\n double std = (double)sqrt(sum1\/n);\n\n printf(\"%.1f\\n\", std);\n\n return 0;\n}<\/pre>\n\n\n\n