C++ math ceil - Syntax
mixed ceil(mixed n);
The ceil() function in C++ is used to return the next highest integer value by rounding up value if necessary.
mixed ceil(mixed n);
mixed n |
Specifies the real number (int, long, float, double) / infinity (*Required) |
---|---|
Return mixed |
Returns a number / infinity respective to an input argument. |
Round the floating point number from 1.0 to 2.0 step by 0.1 using ceiling math method and print the resultant in console.
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, const char * argv[])
{
// Positive floating point value
cout << "The ceiling value of 1.0 is " << ceil(1.0) << endl;
cout << "The ceiling value of 1.1 is " << ceil(1.1) << endl;
cout << "The ceiling value of 1.2 is " << ceil(1.2) << endl;
cout << "The ceiling value of 1.3 is " << ceil(1.3) << endl;
cout << "The ceiling value of 1.4 is " << ceil(1.4) << endl;
cout << "The ceiling value of 1.5 is " << ceil(1.5) << endl;
cout << "The ceiling value of 1.6 is " << ceil(1.6) << endl;
cout << "The ceiling value of 1.7 is " << ceil(1.7) << endl;
cout << "The ceiling value of 1.8 is " << ceil(1.8) << endl;
cout << "The ceiling value of 1.9 is " << ceil(1.9) << endl;
cout << "The ceiling value of 2.0 is " << ceil(2.0) << endl;
return 0;
}
Round the positive floating point number (random numbers) using ceiling math method and print the resultant in console.
#include <iostream>
#include
using namespace std;
int main(int argc, const char * argv[])
{
// Positive floating point value
cout << "The ceiling value of 1.5698 is " << ceil(1.5698) << endl;
cout << "The ceiling value of 1.3093 is " << ceil(1.3093) << endl;
cout << "The ceiling value of 1.0087 is " << ceil(1.0087) << endl;
cout << "The ceiling value of 1.1038 is " << ceil(1.1038) << endl;
cout << "The ceiling value of 1.9573 is " << ceil(1.9573) << endl;
cout << "The ceiling value of 1.7462 is " << ceil(1.7462) << endl;
cout << "The ceiling value of 1.6427 is " << ceil(1.6427) << endl;
cout << "The ceiling value of 1.4128 is " << ceil(1.4128) << endl;
cout << "The ceiling value of 1.8099 is " << ceil(1.8099) << endl;
cout << "The ceiling value of 1.2743 is " << ceil(1.2743) << endl;
cout << "The ceiling value of 2.0001 is " << ceil(2.0001) << endl;
return 0;
}
Round the negative floating point number (random numbers) using ceiling math method and print the resultant in console.
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, const char * argv[])
{
// Positive floating point value
cout << "The ceiling value of -1.5698 is " << ceil(-1.5698) << endl;
cout << "The ceiling value of -1.3093 is " << ceil(-1.3093) << endl;
cout << "The ceiling value of -1.0087 is " << ceil(-1.0087) << endl;
cout << "The ceiling value of -1.1038 is " << ceil(-1.1038) << endl;
cout << "The ceiling value of -1.9573 is " << ceil(-1.9573) << endl;
cout << "The ceiling value of -1.7462 is " << ceil(-1.7462) << endl;
cout << "The ceiling value of -1.6427 is " << ceil(-1.6427) << endl;
cout << "The ceiling value of -1.4128 is " << ceil(-1.4128) << endl;
cout << "The ceiling value of -1.8099 is " << ceil(-1.8099) << endl;
cout << "The ceiling value of -1.2743 is " << ceil(-1.2743) << endl;
cout << "The ceiling value of -2.0001 is " << ceil(-2.0001) << endl;
return 0;
}
Round the infinity using ceiling math method and print the resultant in console.
#include <iostream>
#include <math.h>
#include <limits>
using namespace std;
int main(int argc, const char * argv[])
{
// Positive ∞ infinite value
cout << "The ceiling value of inf is " << ceil(std::numeric_limits<float>::infinity()) << endl;
// Negative ∞ infinite value
cout << "The ceiling value of -inf is " << ceil(-std::numeric_limits<float>::infinity()) << endl;
return 0;
}