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
whats for dinner? please
Consider the follow program that prints a page number on the left or right side of a page. Define and use a new function, isEven, that returns a Boolean to make the condition in the if statement easier to understand. ef main() :   page = int(input("Enter page number: "))   if page % 2 == 0 :      print(page)   else :      print("%60d" % page)   main()
What is the correct python code for the function def countWords(string) that will return a count of all the words in the string string of workds that are separated by spaces.

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++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage