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

Step: 3

blur-text-image

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

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

What are the steps in the T&D process?

Answered: 1 week ago