它将值舍入为不小于给定值的最接近的整数。
例如:
ceil(8.1)=9.0; ceil(-8.8)=-8.0;
假设数字是“ x”。语法为:
double ceil(double x);
x : 四舍五入到最接近的整数的值。
它返回不小于x的最小整数值。
让我们看一个简单的例子,考虑x的正值。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-ceil-function.html
来源:LearnFk无涯教程网
#include <iostream> #include<cmath> using namespace std; int main() { float x=9.2; std::cout << "Initial value of x is :"<<x; cout<<'\n'; cout<<"final value of x is :"<<ceil(x); return 0; }
输出:
Initial value of x is :9.2 final value of x is :10
让我们看一个简单的例子,考虑x的负值。
#include <iostream> #include<cmath> using namespace std; int main() { float x=-2.2; std::cout << "Initial value of x is :"<<x; cout<<'\n'; cout<<"final value of x is :"<<ceil(x); return 0; }
输出:
Initial value of x is :-2.2 final value of x is :-2
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)