In: Computer Science
Write a program that will find the smallest, largest, and average values in a collection of N numbers. Get the value 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 of the data collections. To compute the standard deviation, accumulate the sum of the squares of the data values (sum squares) in the main loop. After the loop exits, use the formula: Standard Deviation = qsum sqaures N − average2 Use a for or while loop, and scan for each number entered separately. sample run 1 Program Computes Average, Maximum, Minimum,and Standard Deviation of N numbers Enter N: 5 Number 1: 19.3 Number 2: 16.5 Number 3: 11.9 Number 4: 22.3 Number 5: 18.4 Average = 17.680 Maximum = 22.300 Minimum = 11.900 StanDev =3.443 (IN C WITH COMMENTS)
#include <stdio.h>
#include <math.h>
//function declarations
double calAvg(double nos[],int n);
double standardDeviation(double nos[],int n,double mean);
double findMin(double nos[],int n);
double findMax(double nos[],int n);
int main()
{
//declaring variables
int n,i;
double mean,variance,std_dev,min,max;
//getting the n value entered by the user
printf("Enter N :");
scanf("%d",&n);
/* creating an double type array of size
* based on the the value of n
*/
double nos[n];
/* getting the values entered by the user
* and populating them into an array
*/
for(i=0;i<n;i++)
{
printf("Number %d:",(i+1));
scanf("%lf",&nos[i]);
}
//Calling the functions
mean=calAvg(nos,n);
std_dev=standardDeviation(nos,n,mean);
min=findMin(nos,n);
max=findMax(nos,n);
//Displaying the average
printf("Average :%.3lf",mean);
//Displaying the maximum value
printf("\nMaximum :%.3lf",max);
//Displaying the minimum value
printf("\nMinimum :%.3lf",min);
//Displaying the standard deviation
printf("\nStandard Deviation :%.3lf",std_dev);
return 0;
}
//This function is used to calculate the average
double calAvg(double nos[],int n)
{
//Declaring local variables
double sum=0.0,mean;
//calculating the sum of nos[] array elements
for(int i=0;i<n;i++)
{
//calculating the sum
sum+=nos[i];
}
//calculating the average
mean=sum/n;
return mean;
}
//This function is used to calculate the standard deviation
double standardDeviation(double nos[],int n,double mean)
{
double variance,std_dev,sum=0.0;
for(int i=0;i<n;i++)
{
sum+=pow(nos[i]-mean,2);
}
//calculating the standard deviation of nos[] array
variance=(double)sum/n;
std_dev=sqrt(variance);
return std_dev;
}
//This function is used to calculate the minimum value
double findMin(double nos[],int n)
{
double min;
int i;
min=nos[0];
for(i=0;i<n;i++)
{
if(min>nos[i])
min=nos[i];
}
return min;
}
//This function is used to calculate the maximum value
double findMax(double nos[],int n)
{
double max;
int i;
max=nos[0];
for(i=0;i<n;i++)
{
if(max<nos[i])
max=nos[i];
}
return max;
}
________________
Output:

_______Thank You