Question
Program: Function floor ( found in the math library ) may be used to round a number to a specific decimal place. The statement: y=
Program:
Function floor (found in the math library) may be used to round a number to a specific decimal place. The statement: y= floor (x * 10 + .5) / 10; rounds x to the tenths position (the first position to the right of the decimal place. The statement y = floor(x*100 +.5) / 100; rounds x to the hundredths position (2nd to the right of decimal place).
Write a program that defines four functions to round a number x in a number of ways: A. float roundToInteger( float number ) B. float roundToTenths(float number ) C. float roundToHundredths( float number ) D. float roundToThousandths( float number ) In your program, ask the user to enter a floating point number. Then, your program should print the original value, the number rounded nearest int, nearest tenth, nearest hundredth and nearest thousandth. Use the math library function floor to calculate.
So, your program will have 5 functions that you created.
main -- where you will ask for a number from the user, and get it.
roundToInteger( number ) roundToTenths( number ) roundToHundredths( number ) roundToThousandths( number )
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started