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

Complete the following 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 (Use 0 to print results). Example of wanted output is at the bottom of the program.

Complete the following program in C, which reads in numbers from the

#include #de fine BUFSIZE 256 int main() int double item- -1 double max; double min; double sum; int howmanY.= 0; // how many valid numbers were read int char ine [BUFSIZE]; // fgets) knows about the NULL itemsread 0; // initial value so loop starts /i check last item wasn't zero; if not // read the line from input and copy it to memory as a string while ( item !=0&& fgets (line, BUFSIZE, stdin) != NULL ) { // scan the number from the line extra stuff on line is ignored itemsread sscanf(line, "slf", &item); // check to see if we got valid input if (itemsread1 && item0) if (howmany0) I this is first item maxitem minitem if item max if item min else t maxitem; min item; howmany+ sum += item; // this will not get stuck in an infinite loop, // plus we can examine the input data if (itemsread0) printf("bad input "); printf("# numbers: if howmany > 0) %d ", howmany); printf("maximum: slf ", max); printf("minimum: f ", min); printf("sum: .. " , sum); return 0 WANTED Result (Output) # items: 5 Sum: 15 Max: 12 Min: -9 Mean: 3

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!