Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 #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)
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started