Write a program that will find the smallest, largest, and average values in a co
ID: 3544025 • Letter: W
Question
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.
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:
Preferably using a for or while loop, and using scan for each number entered separately.
a. and b. (combined)
Below is a sample run
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
Explanation / Answer
#include <stdio.h>
#include<math.h>
int main()
{
float max,min,sum,input,sum_squares;
sum=0;
sum_squares=0;
int N;
int i;
printf("Enter N: ");
scanf("%d", &N);
printf("Number 1: ");
scanf("%f",&input);
sum+=input;
sum_squares+=input*input;
max=input;
min=input;
for(i=1;i<N;i++)
{
printf("Number %d: ",i+1);
scanf("%f",&input);
sum+=input;
sum_squares+=input*input;
if(input>max) max=input;
if(input<min) min=input;
}
printf("Average = %f ",sum/N);
printf("Maximum = %f ",max);
printf("Minimum = %f ",min);
printf("StanDev = %f ",sqrt((sum_squares/N) - (sum/N)*(sum/N) ));
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.