Question
The Output should look like this when run on the command prompt: I'm having trouble with C programming, this is done in Unix, please help
The Output should look like this when run on the command prompt:
I'm having trouble with C programming, this is done in Unix, please help
Source Code Provided:
/* fgets() returns the next line of input, cutting it off if it's * longer than the size of the buffer being read. */
#include
#define BUFSIZE 256
int main() { int itemsread = 0; double item = -1; // initial value so loop starts int howmany = 0; double max; double min; char line[BUFSIZE]; // fgets() knows about the NULL
// 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, "%lf", &item);
// check to see if we got valid input if (itemsread == 1 && item != 0) { if (howmany == 0){ min = item; max = item; } howmany++;
}
// this will not get stuck in an infinite loop, // plus we can examine the input data if (itemsread == 0) { printf("bad input "); } } if (howmany !=0){ printf("Max: %lf ",max); printf("Min: %lf ", min); }else{ printf("No numbers entered "); } printf("# numbers: %d ", howmany);
return 0; }
Write a program in C, that reads in numbers from the keyboard (standard input), one per line, until it detects that a 0 (zero not an 'oh') has been entered. The 0 does not count as part of the number series. After all numbers have been entered print out the number of items entered, the sum, the minimum value entered, the maximum value entered, and the arithmetic mean (one on each line), in the order listed here My Starting Point File is below: /* fgets () returns the next line of input, cutting it off if it's * longer than the size of the buffer being read. #includeStep 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