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
?Which of the following assignment statements is not correct x = ++x; x++ = y + 2; x += ++y; X = x++ + 2;
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!".
1a. It is known that x and n are integers, where x has a value of -1 and n has a value of 5. What is the valueof the following expression? !(++x || n) + 6 - (!n && n * (n < n)) I know this equals 6 but how do I work it out   1a .Compute the values of the following expressions if x is 1, y is 4 and z is 14. Assume thattrue relations have a value of 1 (I want to see how these problems are worked out) 1B. work out each of these. x+5<=z-(x||z)-y  z/y%z-6<=!y  x>=1&&y==3+y||z<14   x-!y-y<=z*z/6>y

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