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
4 Antworten
+ 2
Try using ceil() with required header files.
https://code.sololearn.com/cWf030i39pru/?ref=app
+ 2
You can do something like this 👇
d = m/n;
r = m%n;
if (r >= n/2)
roundedVal = d+1 ;
else
roundedVal = d ;
0
//For C
https://stackoverflow.com/questions/2422712/rounding-integer-division-instead-of-truncating
https://stackoverflow.com/questions/42885659/round-off-float-value-in-c-without-in-built-functions
//For C++
https://stackoverflow.com/questions/44848113/rounding-off-floating-point-value-in-c-without-using-build-in-functions
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)