How to use ceil in C++

2 Answers

0 votes
#include <iostream>
#include <cmath>
 
int main(void) {
    float f1 = 1.1f, f2 = 1.5f, f3 = 1.6f, f4 = 1.9f, f5 = 0.01f;
 
    std::cout << ceil(f1) << "\n";
    std::cout << ceil(f2) << "\n";
    std::cout << ceil(f3) << "\n";
    std::cout << ceil(f4) << "\n";
    std::cout << ceil(f5) << "\n";

    return 0;
}
 
 
 
/*
run:
 
2
2
2
2
1
 
*/

 



answered Jun 10, 2022 by avibootz
0 votes
#include <iostream>
#include <cmath>
 
int main(void) {
    float f1 = -1.1f, f2 = -1.5f, f3 = -1.6f, f4 = -1.9f, f5 = -0.01f;
 
    std::cout << ceil(f1) << "\n";
    std::cout << ceil(f2) << "\n";
    std::cout << ceil(f3) << "\n";
    std::cout << ceil(f4) << "\n";
    std::cout << ceil(f5) << "\n";

    return 0;
}
 
 
 
/*
run:
 
-1
-1
-1
-1
-0

*/

 



answered Jun 10, 2022 by avibootz

Related questions

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