Question: Write a new C program in the file t3.c. Write a program to read a floating point value from standard input, then output the largest

Write a new C program in the file t3.c.

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

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)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!