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 108 views
1 answer 171 views
1 answer 130 views
1 answer 159 views
1 answer 89 views
1 answer 156 views
1 answer 137 views
...