Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

The Output should look like this when run on the command prompt:

image text in transcribed

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. #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, "%f", &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, 7 plus we can examine the input data if (itemsread == 0) { printf("bad input "); if (howmany !=0) { printf("Max: $1f ",max); printf("Min: $1f ", min); jelse{ printf("No numbers entered "); printf("# numbers: %d ", howmany); return 0; Stats 38 ->$./stats 12.54 122334567 89877654 23.456 1.234 -100 65 # items: Sum: Maximum: Minimum: Mean: 212212223.230000 122334567.000000 -100.000000 30316031.890000 Stats 36 ->$./stats items

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

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions