Hello, I am learning c programming and we just finished going over loops. We JUS
ID: 3631326 • Letter: H
Question
Hello, I am learning c programming and we just finished going over loops. We JUST began pointers, but there aren't any used for this program from what the professor said. We also CAN'T use arrays. I don't know a lot of programming so if you could maybe write some comments to explain the code, that would help a lot.
Write a program that computes the average and standard deviation of a set of double values read from a file. The standard deviation of the set of values {xi, i=1, 2,...N} is given by the expression:
S = sqrt[ ((xi)2)/N - (x-bar)2], where i = 1
where is the average value, defined by the expression:
x-bar = (xi)/N, where i = 1
Your program should read data from a file which contains one number per line. The total number of lines is not known before execution of the program. The program should detect the end of file to stop reading the data. It should conform to the following format:
$ ./sdev < file.dat
The average is 23.8733
The standard deviation is 1.4754
I was told that we have to create a file named "file.dat" which draws the values to be used...? I have no idea how to do that. Please help!!
Explanation / Answer
#include #include int calc (float a, float b, float c, float d, float e, float *sum, float *avg,float *sd); int main() { float a, b, c, d, e, sum=0.0, avg=0.0; float sd=0.0; printf("Enter Five Numbers:"); scanf("%f %f %f %f %f",&a,&b,&c,&d,&e); calc (a, b, c, d, e, &sum, &avg, &sd); printf(" Sum=%f", sum); printf(" Average=%f", avg); printf(" Standard Deviation=%f ", sd); getchar(); return 0; } calc (float a, float b, float c, float d, float e, float *sum, float *avg, float *sd) { float Calc=0.0; *sum = a+b+c+d+e; *avg = *sum / 5.0; Calc += ( a - *avg) * ( a - *avg); Calc += ( b - *avg) * ( b - *avg); Calc += ( c - *avg) * ( c - *avg); Calc += ( d - *avg) * ( d - *avg); Calc += ( e - *avg) * ( e - *avg); *sd = sqrt((double)Calc/5.0); }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.