kamito dono kamito dono - 1 year ago 68
C Question

How do I round this int up

Is there any way to round

up. In this case the outcome of
is 5.5 I want it to be 6 how do I do this?

See code below:

int main(void){

int systemGuess = 0;
stystemGuess = (10 - 1)/2 + 1;
printf(" %d ", stystemmGuess);

Answer Source

Use floating point division and ceil:

stystemGuess = ceil((10 - 1)/2.0) + 1;

If you want to round 0.4 down, use round instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download