2. Calculating Average, Variance and Standard Deviation: Write a program that cr
ID: 2266234 • Letter: 2
Question
2. Calculating Average, Variance and Standard Deviation: Write a program that creates an array of 100 random numbers from 17 to 42. Then calculate the average, the variance, and the standard deviation as noted below. Output (print) your random data set and the following calculated statistics for your data set a. Average: The average, like the median, is another measure of central tendency, or where your data tends to be centralized. Calculate the Average as follows Average-sum of all values in your data set) /number of values in your data set b. Variance: The variance is a measure of spread and is calculated as follows: Variance- d1 (zi-1)2 where n is the number of elements in your data set, T is your average, and ri is each value in your data set from the element at index i0 toi n - 1 (the last index of your array) c. Standard Deviation (SD): Standard Deviation is another measure of spread and can be calculated as such: SDvarianceExplanation / Answer
#include<stdio.h>
#include<math.h>
Void main()
{
Int a[99],sum=0;t=0; // values of 0 to 99 gives 100 values
Float av=0;var=0,sd=0;
Printf("give the values between 17 and 42"); //takes the array of values between 17 and 42
For(i=0;i<=99;i++)
{
Scanf("%d",&a[i]);
}
While(i<100)
{
Sum=sum+a[i]; //sum gives sum of all values in your data set
i=i+1;
}
Av=sum/100; //av gives the average value
Printf("average value is %f",av);
i=0;
While(i<100)
{
t=t+((a[i]-av)*(a[i]-av));
i=i+1;
}
Var=t/100; //here n=100 and var gives the variance
Sd=(var^0.5); //sd gives standard deviation
Printf("variance is %f",var);
Printf("standard deviation is %f",sd);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.