Computer Science: A Structured Programming Approach Using C, Third Edition
Computer Science: A Structured Programming Approach Using C, Third Edition
3rd Edition
ISBN: 9780534491321
Author: Behrouz A. Forouzan, Richard F. Gilberg
Publisher: Course Technology, Inc.
Expert Solution & Answer
Book Icon
Chapter 4, Problem 23PS

a.

Explanation of Solution

 Given: The expression is floor (x*10+0.5)/10, where x is 3.5, 3.45, 3.76, 3.234, and 3.4567.

To find: The value of the expression, floor (x*10+0.5)/10, where x is 3.5, 3.45, 3.76, 3.234, and 3.4567.

Solution:

The output of the aforementioned statement, (x*10+0.5)/10, when:

x=3.5

The output of the aforementioned expression will evaluate to 3.500000. On substituting the value of x as 3.5, the expression will be evaluated. Then the function named ‘floor()’ is applied, which will return the largest double value which is smaller than or equal to integer x. The value it will return will be of type, double.

The following is the sample code:

The output of the above function will look like:

x=3.45

The output of the aforementioned expression will evaluate to 3.500000. On substituting the value of x as 3.45, the expression will be evaluated. Then the function named ‘floor()’ is applied, which will return the largest double value which is smaller than or equal to integer x. The value it will return will be of type, double.

The following is the sample code:

The output of the above function will look like:

x=3.76

The output of the aforementioned expression will evaluate to 3.800000. On substituting the value of x as 3.76, the expression will be evaluated. Then the function named ‘floor()’ is applied, which will return the largest double value which is smaller than or equal to integer x...

b.

Explanation of Solution

 Given: The expression is floor (x*100+0.5)/100 where x is 3.5, 3.45, 3.76, 3.234, and 3.4567.

To find: The value of the expression, floor (x*100+0.5)/100, where x is 3.5, 3.45, 3.76, 3.234, and 3.4567.

Solution:

The output of the aforementioned statement, (x*100+0.5)/100, when:

x=3.5

The output of the aforementioned expression will evaluate to 3.500000. On substituting the value of x as 3.5, the expression will be evaluated. Then the function named ‘floor()’ is applied, which will return the largest double value which is smaller than or equal to integer x. The value it will return will be of type, double.

The following is the sample code:

The output of the above function will look like:

x=3.45

The output of the aforementioned expression will evaluate to 3.450000. On substituting the value of x as 3.45, the expression will be evaluated. Then the function named ‘floor()’ is applied, which will return the largest double value which is smaller than or equal to integer x. The value it will return will be of type, double.

The following is the sample code:

The output of the above function will look like:

x=3.76

The output of the aforementioned expression will evaluate to 3.760000. On substituting the value of x as 3.76, the expression will be evaluated. Then the function named ‘floor()’ is applied, which will return the largest double value which is smaller than or equal to integer x...

c.

Explanation of Solution

 Given: The expression is floor (x*1000+0.5)/1000, where x is 3.5, 3.45, 3.76, 3.234, and 3.4567.

To find: The value of the expression, floor (x*1000+0.5)/1000, where x is 3.5, 3.45, 3.76, 3.234, and 3.4567.

Solution:

The output of the aforementioned statement, (x*1000+0.5)/1000, when:

x=3.5

The output of the aforementioned expression will evaluate to 3.500000. On substituting the value of x as 3.5, the expression will be evaluated. Then the function named ‘floor()’ is applied, which will return the largest double value which is smaller than or equal to integer x. The value it will return will be of type, double.

The following is the sample code:

The output of the above function will look like:

x=3.45

The output of the aforementioned expression will evaluate to 3.5. On substituting the value of x as 3.45, the expression will be evaluated. Then the function named ‘floor()’ is applied, which will return the largest double value which is smaller than or equal to integer x. The value it will return will be of type, double.

The following is the sample code:

The output of the above function will look like:

x=3.76

The output of the aforementioned expression will evaluate to 3.760000. On substituting the value of x as 3.76, the expression will be evaluated. Then the function named ‘floor()’ is applied, which will return the largest double value which is smaller than or equal to integer x...

Blurred answer
Students have asked these similar questions
x = 9 ; y = x++ What are the values of x and y after the two statements execute? X = y =
Write a main function that performs the following: • Prompts user to enter 2 values A and B. . If the first number A is less than the second number B, the main function should print the sum of all numbers multiple of 2 from 1 to A. • If the first number A is greater than the second number B, the main function should print the product of all numbers multiple of 4 from 1 to B. • If not, the main function should display "Wrong data. Try again!".
Write a main function that performs the following: • Prompts user to enter 2 integer values A and B. • if the first number A is greater than to B+5, the main function prints out the result of 6 multiplied with the every odd number from 1 to B... • If the first number A is less than or equal to B+5, the main function prompts the user A times to enter grades in a variable called grade and print their summation. • If not, it prints out "No output to be given".

Chapter 4 Solutions

Computer Science: A Structured Programming Approach Using C, Third Edition

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning