0

how to round division of any number without math round() fx in c and c++?

for ex ((2*100)/3) should be 66.67 so its rounded value must be 67

3rd Jan 2022, 3:03 AM
Harshit Mishra
Harshit Mishra - avatar
4 Respostas
+ 2
Try using ceil() with required header files. https://code.sololearn.com/cWf030i39pru/?ref=app
3rd Jan 2022, 3:15 AM
Simba
Simba - avatar
+ 2
You can do something like this 👇 d = m/n; r = m%n; if (r >= n/2) roundedVal = d+1 ; else roundedVal = d ;
3rd Jan 2022, 4:06 AM
saurabh
saurabh - avatar
0
Harshit Mishra Here's something you could do: float num = 66.67; int floored = (int) num; int result = floored+(num-floored>=0.5); (Not sure if this is the right way to do it as it's been a long time since I've brushed up on my C skills)
3rd Jan 2022, 6:27 AM
Œ ㅤ
Œ ㅤ - avatar