Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

-- Write a program to read a floating point value from standard input, then output the largest integer smaller than or equal to this value;

-- Write a program to read a floating point value from standard input, then output the largest integer smaller than or equal to this value; the nearest integer to this value, with halfway values rounded away from zero; the smallest integer larger than or equal to this 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".

Sample input: 3.1415

Corresponding output: 3 3 4

q2-

Copy your solution t3.c to the new file t4.c.

The input is guaranteed to contain at least one non-whitespace character.

If the input is well-formed, i.e., can be parsed to a number, the program should behave identically to Task 3: all the requirements of Task 3 still apply except the file name.

If the input is not well formed, the program should print a helpful error message that contains the value returned by scanf() so that the programmer can compare this number with the scanf() documentation to figure out what went wrong. (If this program was aimed at end-users, we might design this differently).

The error message should be in the form:

"scanf error: (%d) "

with the scanf() return value between the parentheses.Sample input:

3.1415

Corresponding output:

3 3 4

Sample input:

sausage

Corresponding output:

scanf error: (0)

q3 --

Write a 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. " on line by itself, then exit the program.

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 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 

q4--

Read floating point values from stdin, each separated by a newline, and terminated by EOF.

The input values are in the range [-100,000 to +100,000].

The input will contain at least one floating-point value.

The input may contain blank lines: these should be ignored.

Apart from possible blank lines, the input is otherwise well-formed.

At EOF, output:

the smallest value seen

the largest value seen

the arithmetic mean of all the values seen

all accurate to two decimal places.

The output values must be separated by a single space character and followed by a newline character.

Examples:Input:

7 5.6 6

Output:

5.60 7.00 6.20

Input:

11

Output:

11.00 11.00 11.00

q5--

Read an arbitrary number of positive integer values from stdin. The values are separated by one or more spaces or newlines (only).

The input is guaranteed to be well-formed.

On standard output, render a a simple graph representation of the input values, in order, using hash '#' characters as shown in the examples below. The number of hashes printed should be equal to the input value.

Your program should output exactly one line per input value.

The value zero should generate an empty line, i.e. just a newline character.

Ignore empty lines. Do not output a newline for an empty line.

Guide

Examples

Input:

5 4 3 2 1

Output:

##### #### ### ## # 

Input:

16 0 4 12

Output:

################ #### ############ 

Input:

1 1 3 2 1

Output:

# # ### ## # 

Input:

3 2 1 

Output:

### ## # 

Guide

Again your and output are interleaved in the terminal window, so the appearance of a run of a correct program with first example above is:

5 4 3 2 1 ##### #### ### ## # 

But the third example is more messy since the input contained several lines:

1 1 3 # # ### 2 1 ## # 

In the next lab we will see how to use files with stdin and stdout to avoid this unsightly mess.

Testing & Submission

As usual. Don't forget the requirement that the program accepts arbitarily large input, including empty and very large. Test these cases.

When testing yourself, don't forget to try small values and ensure that your rendering meets the specifications.

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

Students also viewed these Databases questions

Question

Explain the different types of marketing strategies.

Answered: 1 week ago

Question

Explain product positioning.

Answered: 1 week ago