Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please as soon as possible I need to use any loop ( if , for statement) Write a

ID: 3678789 • Letter: P

Question

Please as soon as possible I need to use any loop ( if , for statement)

Write a program that will find the smallest, largest, and average values in a collection of N numbers. Get the value of 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 collection. To compute the standard deviation, accumulate the sum of the squares of the data values (sum_squares) in the main loop. After loop exit, use the formula

Explanation / Answer

#include<stdio.h>
#include<math.h>

double standard_deviation (double sum_squares, double N, double average);

int main()
{
int count;
double N[30];
double n;
int i=0;
double sum, average;
double small,large=0;
double sum_squares, st_dev;


sum = 0.0;
average = 0.0;
count = 0;

printf("How many number?" );
scanf("%lf",&n);
printf("Enter %lf number and <Enter> after each> ", n);

for(i=0;i<n;i++){
   scanf("%lf",&N[i]);
   sum= sum + N[i];
}
average= sum / (double) n;
sum_squares = pow(sum, 2);

small = N[0];
large = N[i-1];
while (count < n){
  
if (large < N[count])
   large = N[count];
if(small > N[count])
small = N[count];
count++;
}
/* function call */
st_dev = standard_deviation (sum_squares, n, average);

/* print the result */
printf(" Average=%.2f", average);
printf(" Smallest=%.2f", small);
printf(" largest=%.2f", large);
printf(" Standard Deviation is %.2f ", st_dev);

return (0);

}


double standard_deviation (double sum_squares, double N, double average)

{
double stand_dev;
stand_dev = sqrt((sum_squares / N) - pow(average, 2));
return (stand_dev);

}