In this challenge, we practice calculating standard deviation. Check out the Tutorial tab for learning materials and an instructional video!
Given an array, , of integers, calculate and print the standard deviation. Your answer should be in decimal form, rounded to a scale of decimal place (i.e., format). An error margin of will be tolerated for the standard deviation.
The sum of the array values is and there are elements. The mean is .
Subtract the mean from each element, square each result, and take their sum.
Their sum is 18. Take the square root of to get , the standard deviation.
Complete the stdDev function in the editor below.
stdDev has the following parameters:
- int arr[n]: an array of integers
- float: the standard deviation to 1 place after the decimal
The first line contains an integer, , denoting the size of arr.
The second line contains space-separated integers that describe .
Print the standard deviation on a new line, rounded to a scale of decimal place (i.e., format).
STDIN Function ----- -------- 5 arr size n = 5 10 40 30 50 20 arr =[10, 40, 30, 50, 20]
First, find the mean:
Next, calculate the squared distance from the mean, , for each :
Now compute , so: