This is a program writing in c code Using include and other
This is a program writing in c code. Using #include <studio.h> and other c libraries.
A. 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:
Preferably using a for or while loop, and using scan for each number entered separately.
((((((Notes: 1) Your code should include separate functions to calculate the maximum, minimum, average, and standard deviation values.
2) Assume that the numbers are coming from a file called “data.txt”. [supplied] - You can call to this i will have the file.
3) Assume that the file will never contain more than 200 numbers.
4) Remember to check that the file to be read exists and to check for EOF when reading in the data. )))))))))
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
Solution
//C Program
#include <stdio.h>
#include <math.h>
float calculateSD(float data[],size);
float calculateAvg(float data[],size);
int main()
{
int i,size;
float data[10];
printf(\"Enter number of elements: \");
scanf(\"%f\", &size);
for(i=0; i < 10; ++i)
scanf(\"%f\", &data[i]);
//Avg cal
printf(\"\ Standard Deviation = %.6f\", calculateAvg(data,size));
//Maximum number cal
big=data[0];
for(i=1;i<size;i++){
if(big<data[i])
big=data[i];
}
printf(\"Maximum : %d\",big);
//Minimum number cal
small=data[0];
for(i=1;i<size;i++){
if(small>data[i])
small=data[i];
}
//Standard Deviation cal
printf(\"Minimum : %d\",small);
printf(\"\ Standard Deviation = %.6f\", calculateSD(data,size));
return 0;
}
float calculateSD(float data[],int size)
{
float sum = 0.0, mean, standardDeviation = 0.0;
int i;
for(i=0; i<size; ++i)
{
sum += data[i];
}
mean = sum/10;
for(i=0; i<10; ++i)
standardDeviation += pow(data[i] - mean, 2);
return sqrt(standardDeviation/10);
}
float calculateAvg(float data[],int size)
{
float sum = 0.0, mean;
int i;
for(i=0; i<size; ++i)
{
sum += data[i];
}
mean = sum/10;
return mean;
}

