Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program called stats that reads doubles from a file given as a command line argument, puts them into an array, and computes

image text in transcribedimage text in transcribed

Write a C program called stats that reads doubles from a file given as a command line argument, puts them into an array, and computes statistics for them. You will need to read the file twice. The first time, just count the number of input items. Then you can create the array and read the items into the array. After reading the file to count the numbers, use rewind to reset the file position to the beginning so that you can read the numbers again. You will define the following functions: - int count(FILE in) will count the items in the input stream. - void read_numbers(FILE*in, int n, double a[n] ) will read the numbers into the array. - double sum(int n, double a[n] ) will return the sum of the numbers in the array. - double mean(int n, double a[n] ) will return the mean (average) of the numbers in the array. - double variance(int n, double a[n] ) will return the variance of the numbers in the array. - double stddev(int n, double a[n] ) will return the standard deviation of the numbers in the array. - double median(int n, double a[n] ) will return the median. The standard deviation is the square root of the variance. You can compute the square root using the function sqrt. The variance is the following sum: ((a[0])2+(a[1])2++(a[n1])2) where is the mean. The median is the middle number in the array if the size is odd and the average of the two middle numbers in the array if the size is even. To compute the median, sort the array using qsort, which is an implementation of quicksort. qsort requires a comparison function which is tricky. Here is one that will work: int compare (const void x, const void y){ double x=( double ) x; double yy=( double )y; if (xx=y) return ; else if (xx

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

7. Where Do We Begin?

Answered: 1 week ago

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago