0
6.4kviews
Explain the following functions: floor(), ceil(), trunc(), sqrt()

Mumbai University> FE > Sem 2> STRUCTURED PROGRAMMING APPROACH

Marks: 4 M

Year: Dec 2016

1 Answer
1
633views

floor()

Returns the largest integer value less than or equal to of given value.

Example:

floor(1.6) returns 1

floor(3.1) returns 3

floor(5.0) returns 5

floor(-1.6) returns -2

ceil()

Returns the smallest integer value greater than or equal to given value.

Example:

ceil(1.6) returns 2

ceil(5.0) returns 5

ceil(3.1) returns 4

trunc()

Returns the largest integer value less than or equal to of given value.

For positive numbers, trunc and floor give the same result. But for negative numbers, floor rounds down and trunc rounds up. This is because trunc always rounds toward 0.

Example:

trunc(1.6) returns 1

trunc(3.1) returns 3

trunc(5.0) returns 5

trunc(-1.6) returns -1

sqrt()

Returns the square root of given value.

Example:

sqrt(25) returns 5

Please log in to add an answer.