In C programming: a. Write a program that will find the smallest, largest amd av
ID: 663434 • Letter: I
Question
In C programming:
a. Write a program that will find the smallest, largest amd average values in a collection of N numbers. Get the value of N before scanning each value in the collection of N numbers.
b. Modify your program to compute and display both the range of values in the data collection and the standard deviation to the data collection. To compute the standard deviation, accumulate the sum of the squares of the data values (sum_squares) in the main loop. After the loop exit, use the formula, standard deviation = square root(sum_squares/N - average^2)
Explanation / Answer
#include <stdio.h>
#include <math.h>
int main ()
{
int i, n;
double a[20], max, min,avg;
printf ("Please enter the number of numbers u want to add ");
scanf ("%d", &n);
printf ("Please enter the numbers ");
for (i = 0; i < n; i++)
{
if(i==0){
scanf ("%lf",&a[i]);
max=a[0];
min=a[0];
avg=a[0];
}
else{
scanf ("%lf",&a[i]);
avg=avg+a[i];
if (a[i] > max)
{
max = a[i];
}
else if (a[i] < min)
{
min = a[i];
}
}
}
avg=avg/n;
printf (" Largest number is: %lf Smallest number is: %lf the average is: %lf ", max, min,avg);
double range=max-min;
printf("Range of the entered values:%lf ",range);
double sum_squares=0;
for(i=0;i<n;i++){
sum_squares=sum_squares+(a[i]*a[i]);
}
double standardDeviation=sqrt((sum_squares/(n-(avg*avg))));
printf("STANDARD DEVIATION:%lf ",&standardDeviation);
return 0;
}