How to use ceil in C

2 Answers

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

int main(void) {
    float f1 = 1.1f, f2 = 1.5f, f3 = 1.6f, f4 = 1.9f, f5 = 0.01f;

    printf("%.1f\n", ceil(f1));
    printf("%.1f\n", ceil(f2));
    printf("%.1f\n", ceil(f3));
    printf("%.1f\n", ceil(f4));
    printf("%.1f\n", ceil(f5));

    return 0;
}



/*
run:

2.0
2.0
2.0
2.0
1.0

*/

 



answered Jun 10, 2022 by avibootz
0 votes
#include <stdio.h>
#include <math.h>

int main(void) {
    float f1 = -1.1f, f2 = -1.5f, f3 = -1.6f, f4 = -1.9f, f5 = -0.01f;

    printf("%.1f\n", ceil(f1));
    printf("%.1f\n", ceil(f2));
    printf("%.1f\n", ceil(f3));
    printf("%.1f\n", ceil(f4));
    printf("%.1f\n", ceil(f5));

    return 0;
}



/*
run:

-1.0
-1.0
-1.0
-1.0
-0.0

*/

 



answered Jun 10, 2022 by avibootz

Related questions

2 answers 134 views
134 views asked Jun 10, 2022 by avibootz
1 answer 130 views
130 views asked Nov 29, 2022 by avibootz
1 answer 127 views
127 views asked Oct 7, 2022 by avibootz
1 answer 174 views
174 views asked Aug 4, 2020 by avibootz
2 answers 203 views
...