I am confused between floor(), ceil() and round() functions in C Programming. Could you please explain it down here? 🙏🥺 | SoloLearn: Learn to code for FREE!

+7

I am confused between floor(), ceil() and round() functions in C Programming. Could you please explain it down here? 🙏🥺

What difference do they all have? Please explain me this topic, I would be so grateful! 🙏🥺

1/21/2021 6:55:01 AM

Mahima Rajvir Singh

9 Answers

New Answer

+15

FLOOR - To get the floor, just remove the decimal next to it. (round down) 2.8 --> 2 CEIL - To get the ceil, just remove the decimal next to it then add 1 (round up) 2.2 --> 3 For negative numbers, just do the opposite. ROUND Get the Floor if next decimal is less than 5. Get the Ceil if next decimal is greater or equal to 5. 2.1 --> 2 2.2 --> 2 2.3 --> 2 2.4 --> 2 2.5 --> 3 2.6 --> 3 2.7 --> 3 2.8 --> 3 2.9 --> 3

+11

round is mathematical rounding: 2.2 -> 2 2.6 -> 3 ceil is always rounding up: 2.2 -> 3 2.6 -> 3 floor is rounding down: 2.2 -> 2 2.6 -> 2

+7

Mahima Rajvir Singh Floor --> Lower integer Ceil --> Higher integer floor( -1.5 ) -2 since -2 is smaller than - 1.5 ceil( -1.5 ) -1 since -1 is larger than -1.5

+7

https://code.sololearn.com/cKo0Qw9xZtO6/?ref=app

+6

Lisa Thanks for your explanation! It means a lot 😊

+6

Aditya Mishra Thank you! This trick was really amazing! 😄

+5

《 Nicko12 》 and Lisa Can you please tell me about the negative numbers? For example: floor(-2.1) ? ceil(-2.1) ? Here, I get confused!

+5

《 Nicko12 》 Thanks! It was helpful 🙏

+4

See there a trick floor means down so if any no. like 25.6 it will go down remaining 25. And in ceil it means top so if any no. like 25.6 is taken it'll go up that's 26. In round function that's pretty simple if value after . is greater than 5 then add 0.5 to the no. otherwise let it be as it is.