3 a Write a C Program to input the following integer numbers
3 a. Write a C Program to input the following integer numbers into an array named grades: 89, 95, 72, 83, 99, 54, 86, 75, 92, 73, 79, 75, 82, 73. As each number is input, add the numbers to the total. After all numbers are input and the total is obtained, calculate the average of the numbers and use the average to determine the deviation of each value from the average. Store each deviation in an array named deviation. Each deviation is obtained as the element value less the average of all the data. Have your program display each deviation alongside its corresponding element from the grades array.
b. Calculate the variance of the data used in Exercise 3a. The variance is obtained by squaring each individual deviation and dividing the sum of the squared deviations by the number of deviations.
Solution
#include <stdio.h>
int main()
{
int grades[1000];
double dev[1000];
int i,r,total=0;
double avg;
printf(\"How many integers are you going to enter:\");
scanf(\"%d\",&r);
printf(\"Please enter %d numbers separated by spaces:\",r);
for(i=0;i<r;i++)
{
scanf(\"%d\",&grades[i]);
total = total + grades[i];
}
avg = (total*1.0)/r;
printf(\"Number and its deviation:\ \");
double var=0;
for(i=0;i<r;i++)
{
dev[i] = avg - grades[i];
printf(\"%d %lf\ \",grades[i],dev[i]);
var += dev[i]*dev[i];
}
var = var/r;
printf(\"The variance of the data is %lf\ \",var);
double s;
return 0;
}
