C++ for Engineers and Scientists
C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
bartleby

Videos

Textbook Question
Book Icon
Chapter 6.2, Problem 11E

(Numerical) a. The following is an extremely useful programming algorithm for rounding a real number to n decimal places:

Step 1: Multiply the number by 10 n

Step 2: Add 0.5

Step 3: Delete the fractional part of the result

Step 4: Divide by 10 n

For example, using this algorithm to round the number 78.374625 to three decimal places yields:

S t e p   1 :   78.374625   ×   103   =   78374.625 S t e p   2 :   78374.625   +   0.5   =   78375.125 S t e p   3 :   R e t a i n i n g   t h e   i n t e g e r   p a r t   =   78375 S t e p   4 :   78375   d i v i d e d   b y   103   =   78.375

Using this algorithm, write a C++ function that accepts a user-entered value and returns the result rounded to two decimal places.

b. Enter, compile, and run the program written for Exercise 11a.

Blurred answer
Students have asked these similar questions
44. What is the value of the following expression:24//6%3, 24//4//2               a. (1,3) b. (0,3) c. (1,0) d. (3,1)
For each of the following statements, state whether it is True or False.
Fill in the blanks to rewrite the following statement with variables: “Is there an integer with a remainder of 1 when it is divided by 4 and a remainder of 3 when it is divided by 7?” (a) Is there an integer n such that n has ____________ ? (b) Does there exist ___________ such that if n is divided by 4 the remainder is 1 and if ___________?
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
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
Boolean Algebra - Digital Logic and Logic Families - Industrial Electronics; Author: Ekeeda;https://www.youtube.com/watch?v=u7XnJos-_Hs;License: Standard YouTube License, CC-BY
Boolean Algebra 1 – The Laws of Boolean Algebra; Author: Computer Science;https://www.youtube.com/watch?v=EPJf4owqwdA;License: Standard Youtube License