Question

In: Computer Science

Write a program that will find the smallest, largest, and average values in a collection of...

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)

Solutions

Expert Solution

#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


Related Solutions

1. Write a program that computes the smallest and largest of a set of values that...
1. Write a program that computes the smallest and largest of a set of values that are stored in an array. Ask the user for the set size (and hence the array size). Populate the array with user input.
1. Write a program that computes the smallest and largest of a set of values that...
1. Write a program that computes the smallest and largest of a set of values that are stored in an array. Ask the user for the set size (and hence the array size). Populate the array with user input. (Java language)
Write a Java program to get the difference between the largest and smallest values in a...
Write a Java program to get the difference between the largest and smallest values in a user inputed array of integers. The length of the array must be 1 and above
• Write a C++ program to find the largest umber, smallest number and sum of all...
• Write a C++ program to find the largest umber, smallest number and sum of all the element of a given array of 20 integers • Note − Declare array to 20 numbers − Input values for 20 array elements − Find largest number − Find smallest number − Find sum of all numbers • Display the results
Write a program to read in a collection of integer values, and find and print the...
Write a program to read in a collection of integer values, and find and print the index of the first occurrence and last occurence of the number 12. The program should print an index value of 0 if the number 12 is not found. The index is the sequence number of the data item 12. For example if the eighth data item is the only 12, then the index value 8 should be printed for the first and last occurrence....
Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values.
 in Coral Simulator  Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. If the input is 7 15 3, the output is: largest: 15 smallest: 3 Your program should define and call two functions: Function LargestNumber(integer num1, integer num2, integer num3) returns integer largestNum Function SmallestNumber(integer num1, integer num2, integer num3) returns integer smallestNum The function LargestNumber should return the largest number of the...
Let A and B be two events. Find the largest and smallest possible values P(A U...
Let A and B be two events. Find the largest and smallest possible values P(A U B) can take in terms of P(A) and P(B) and give examples in which these values can be attained.
Write two algorithms to find both the smallest and largest numbers in a list of n...
Write two algorithms to find both the smallest and largest numbers in a list of n numbers. In first algorithm, you simply write one loop to find the minimum and maximum. So there will be 2(n - 1) comparisons. In second algorithm, you try to find a method that does at most 1.5n comparisons of array items. Determine the largest list size (i.e., n) that Algorithm 1 can process and still compute the answer within 60 seconds. Report how long...
Write a JavaScript program that computes the average of a collection of numbers and then outputs...
Write a JavaScript program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
Write a FORTRAN program that computes the average of a collection of numbers and then outputs...
Write a FORTRAN program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT