Question: he floor ( ) function rounds a number to the nearest integer toward minus infinity. You want to instead round any given number toward zero

he floor() function rounds a number to the nearest integer toward minus infinity. You want
to instead round any given number toward zero (effectively clipping all values after the decimal
point, such that 2.63 rounds to 2, while -2.63 rounds to -2 instead of -3). To do this, in this
problem you must nest some combination of the built-in functions floor(), abs(), and sign().
Note that abs() returns the absolute value of a number, and sign() returns the sign of a number
(1 for positive and -1 for negative). For example, sign(3.4) returns a value of 1, and
sign(-6) returns -1. Using this knowledge, write 4 lines of code that will do the following:
Line 1: Assign a value of -4.8 to a variable called var1
ENME/ENAE 202, University of Maryland 2
Line 2: Assign a value of 4.8 to a variable called var2
Line 3: Construct a single statement to round var1 toward zero (and display the result). Assign
the value to var3
Line 4: Repeat line 3 for var2. Assign to var4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!