Question: Write a program in C which reads in numbers from the keyboard, one per line, until it gets a zero. Then print out (in this


Write a program in C which reads in numbers from the keyboard, one per line, until it gets a zero. Then print out (in this order) the number of values entered, the sum of all values, the largest number, the smallest number, and the average of all the numbers. Do not count the zero. (So, if you read in 4, 8, and 0, the average is 6, because only two numbers were entered before the zero.) Here is sample output from one version of the program:

 % ./stats 2 4 6 12 -9 0 # items: 5 Sum: 15 Max: 12 Min: -9 Mean: 3 %
I just need the part that needs to finish the program. HELP PLEASE  Write a program in C which reads in numbers from the

#include #include #define BUFSIZE 256 int main(int argc, char *argv[]) double item = -1; // initial value so loop starts double sum = 0; // total of all numbers read int count = 0; // number of items read int itemsread; // number of items on one line double hi_num= 0; // highest number read double lo_num = ; // lowest number read char line[BUFSIZE]; // fgets() won't go over the limit int line_num= 0; // number of this line // read one line from input while ( item != 0 && fgets(line, BUFSIZE, stdin) != NULL) { // scan for a number itemsread = sscanf(line, "%1f", &item); // check for valid input if (itemsread == 1 && item != 0) { // THIS PART DOES SOMETHING WITH THE VALID INPUT // WRITE IT BASED ON WHAT YOU DID FOR HOMEWORK 1 if (itemsread == 0) { // input was invalid // put code here to count bad lines printf("# items: %10d ", count); if (count > 0) { printf("Sum: %16.51f ", sum)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!