Calculating Average, Variance and Standard Deviation: Write a program that creat
ID: 3573296 • Letter: C
Question
Calculating Average, Variance and Standard Deviation: Write a program that creates an array of random numbers from 17 to 42. Then, calculate the average, the variance and the standard deviation as noted below. Output your random data set and the following calculated statistics for your data set.
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
Variance: The variance is a measure of spread and is calculated as follows:
Variance = where n is the number of elements in your data set, is your average, and is each value in your data set from the element at index i = 0 to i = n – 1 (the last index of your array).
Standard Deviation (SD): Standard Deviation is another measure of spread and can be calculated as such:
SD= squareroot(variance)
PLEASE USE C LANGUAGE AND SHOW PROOF THAT IT WORKS
Explanation / Answer
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void) {
int start,end,count,ran,i,sum=0,avg=0;
int varn=0,stddiv=0;
printf("enter start limit:");
scanf("%d",&start);
printf("enter end limit:");
scanf("%d",&end);
count=end-start;
int arr[count];
for(i=0;i<count;i++){
ran=(rand()%(end+1-start))+start;
arr[i]=ran;
printf(" %d",arr[i]);
}
for(i=0;i<count;i++)
sum+=arr[i];
avg=sum/count;
printf(" average is:%d",avg);
for(i=0;i<count;i++)
varn+=pow(arr[i] - avg, 2);
printf(" variance is:%d",varn);
stddiv=sqrt(varn);
printf(" standard deviation is :%d",stddiv);
return 0;
}
output:
enter start limit:3
enter end limit:12
6
9
10
8
6
8
9
5
12
average is:8
variance is:39
standard deviation is :6
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.