Write a program that will find the smallest, largest, and average values in a co
ID: 3623128 • 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.
Explanation / Answer
please rate - thanks
#include <stdio.h>
#include <math.h>
#include <conio.h>
double mean(double [],int,double*);
double standardd(double[],int, double);
double calc(double, double);
double maxx(double[],int);
double minn(double[],int);
int main()
{double x[100];
int i=0,j,n;
double average,sd,sum=0;
printf("How many numbers do you have: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{printf("Enter number %d: ",i+1);
scanf("%lf",&x[i]);
}
printf(" Your numbers are: ");
for(j=0;j<n;j++)
printf("%.2f ",x[j]);
printf(" ");
average=mean(x,i,&sum);
sd=standardd(x,i,average);
printf(" The sum of the numbers is %.2f ",sum);
printf("The smallest number is %.2f ",minn(x,n));
printf("The largest number is %.2f ",maxx(x,n));
printf("The average is %.2f ",average);
printf("The standard deviation is %.2f ",sd);
getch();
return 0;
}
double maxx(double x[],int n)
{int i;
double m;
m=x[0];
for(i=1;i<n;i++)
if(x[i]>m)
m=x[i];
return m;
}
double minn(double x[],int n)
{int i;
double m;
m=x[0];
for(i=1;i<n;i++)
if(x[i]<m)
m=x[i];
return m;
}
double mean(double x[],int n,double* sum)
{int i;
for(i=0;i<n;i++)
*sum=*sum+x[i];
return (double)*sum/n;
}
double calc(double x,double avg)
{double temp;
temp=x-avg;
return temp*temp;
}
double standardd(double x[],int n, double average)
{double mean,sum=0;
int i;
for(i=0;i<n;i++)
sum+=calc(x[i],average);
mean=sum/n;
return sqrt(mean);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.