Write a C program that will find the smallest, largest, and average values in a
ID: 3566584 • Letter: W
Question
Write a C 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: Standard Deviation = Preferably using a for or while loop, and using scan for each number entered separately.note: the collection of n numbers should be from a data file called hw1_data.txt with no more than 200 numbers in the file at any time, remember to include check for eof). smallest, largest, mean, and standard deviation should all be calculated in 4 separate functions with the following prototypes: 1. double smallest (double x[], int size); 2. double largest (double x[], int size); 3. double average (double x[], int size); 4. double sigma (double x[], double data_avg, int size);
Explanation / Answer
#include <stdio.h>#include <stdlib.h>
#define pause system("pause")
main(){
//n = amount of numbers input
//x = number given by user
//s = smallest number
//l = largest number
int x = 1, n = -1, s = 999, l = -1;
float sum = -1;
while(x != 0){
printf("Enter a number: (0 to quit) ");
scanf("%d", &x);
sum += x;
n = n + 1;
}
printf("Numbers entered: %i ", n);
if(x < s){
s = x;
printf("Smallest number: %i ", s);
}
if(x > l){
l = x;
printf("Largest number: %i ", l);
}
printf("Average: %.2f ", sum/n);
pause;
}
OR
void stupid(void)
{
printf("This program that will finds the smallest,
");
printf("largest, and average value in a collection of n numbers
");
}
int main()
{
int n;
int a[5];
double i_hope;
double this_will_work;
stupid();
printf("You can enter up to 5 different numbers for this collection of numbers
");
printf("Enter the numbers:");
for(n = 0; n < 5; n++) { scanf("%d", &a[n]);
/* scanf apparently works only for integers and characters/strings */
printf(" %d
", a[n]); }
printf("were the values you entered
");
printf("
");
i_hope = ceil(a[n]);
{ printf("%lf
", i_hope ); }
printf(" was the smallest value entered
");
printf("
");
this_will_work = floor(a[n]);
{ printf(" %lf
", this_will_work ); }
printf("was the largest value entered
");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.