SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 211 Weeks Ago, 4 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 06 Nov 2017 My Price 9.00

Write program to read any number of floating point

  • Question:Write program to read any number of floating point values from standard input, separated by newlines.
  • The input may also contain any number of blank lines, i.e. lines that contain any amount of whitespace followed by a newline.
  • With the exception of blank lines, the input is guaranteed to be well-formed and contain at least one valid floating point value.
  • For each value input, output (as before):The largest integer smaller than this value;
  • The nearest integer to this value, with halfway values rounded away from zero;
  • The smallest integer larger than this value
  • For each input value, the output integers should be separated by a space character and followed by a newline character.
  • The output values should not have any trailing zeros: e.g., "2" not "2.0".
  • If no floating point value can be parsed (i.e. a blank line was read) there should be no output. To put it another way: blank lines should be ignored.
  • The program should accept input values on stdin until EOF is reached.
  • When EOF is reached, print Done.n on line by itself, then exit the program. This line has a . at the end of it. Pay attention to small details.
  • Sample input:
3.1415
7.11
-15.7
  • Corresponding output:
3 3 4
7 7 8
-16 -16 -15
Done.

Important Note: Your input and output are interleaved in the terminal window, so if you type in the numbers and press enter after each line then the appearance of a run of a correct program with the input above is:

3.1415
3 3 4
7.11
7 7 8
-15.7
-16 -16 -15

It's important to realize that the above output consists of alterating line of input and output, each three lines long.

If you construct the input and feed it using shell commands you will see only the output of your program

cc -o t5 t5.c
echo "3.1415 7.11 -15.7" | tr ' ' 'n' | ./t5

Then the output will be

3 3 4
7 7 8
-16 -16 -15
Done.

 

 

Help, I'm stuck with how to use the EOF. This is my code so far:

 

#include<stdio.h>

#include<math.h>

 

int main( void )

{

    float i = 0;

 

    while (!EOF) {

 

        scanf("%fn", &i);

 

        printf("%d ", (int) floor(i));

        printf("%d ", (int) round(i));

        printf("%dn", (int) ceil(i));

    }

 

    printf("Done.n");

}

 

when I compile this it's just display "Done."

 

Please help to fix this!

Answers

(5)
Status NEW Posted 06 Nov 2017 12:11 PM My Price 9.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)