PPA-10
Question
Accept a real number \(x\) as input and print the greatest integer less than or equal to \(x\) on the first line, followed by the smallest integer greater than or equal to \(x\) on the second line.
Hint
The crux of this problem is to look at three cases, two of which are given below:
- What happens when \(x\) is positive?
- What happens when \(x\) is negative?
Here is another hint:
int(3.3)
retains the integer part while truncating whatever comes after the decimal, including the decimal point. Try out the following:
Can you now go ahead and construct a solution for this problem? These are the floor and ceiling functions that we study in mathematics. Why do you think these functions have been named in this manner?