+ 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! 🙏🥺

21st Jan 2021, 6:55 AM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar
9 Réponses
+ 17
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
21st Jan 2021, 7:03 AM
noteve
noteve - avatar
+ 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
21st Jan 2021, 7:05 AM
Lisa
Lisa - avatar
+ 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
21st Jan 2021, 7:18 AM
noteve
noteve - avatar
+ 7
Lisa Thanks for your explanation! It means a lot 😊
21st Jan 2021, 7:24 AM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar
22nd Jan 2021, 3:56 PM
Hrutik Bhalerao
Hrutik Bhalerao - avatar
+ 6
Aditya Mishra Thank you! This trick was really amazing! 😄
22nd Jan 2021, 5:03 AM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar
+ 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!
21st Jan 2021, 7:15 AM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar
+ 5
《 Nicko12 》 Thanks! It was helpful 🙏
21st Jan 2021, 7:22 AM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar
+ 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.
22nd Jan 2021, 2:36 AM
Aditya Mishra