How to round up the result of integer division in C

1 Answer

0 votes
#include <stdio.h>
#include <math.h>

int main() {
    int a = 247, b = 9;
    
    double result = (double)a / b;
    int result_round_up = (int)ceil((double)a / b);
    
    printf("%f\n", result);
    printf("%d\n", result_round_up);
    
    return 0;
}

   
    
/*
run:
     
27.444444
28
   
*/

 



answered Dec 4, 2024 by avibootz

Related questions

1 answer 105 views
1 answer 164 views
1 answer 124 views
1 answer 149 views
1 answer 82 views
1 answer 148 views
1 answer 130 views
...