它將值四舍五入到不小於給定值的最接近的整數。
例如:
ceil(8.1)=9.0;
ceil(-8.8)=-8.0;
用法
假設一個數字是 'x'。語法是:
double ceil(double x);
參數
x: 它是四舍五入到最接近的整數的值。
返回值
它返回不小於 x 的最小整數值。
例子1
讓我們看一個簡單的例子,考慮 x 的正值。
#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
例子2
讓我們看一個簡單的例子,考慮 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
相關用法
- C++ Math cosh()用法及代碼示例
- C++ Math cos()用法及代碼示例
- C++ Math copysign()用法及代碼示例
- C++ Math cbrt()用法及代碼示例
- C++ Math scalbn()用法及代碼示例
- C++ Math acosh()用法及代碼示例
- C++ Math asinh()用法及代碼示例
- C++ Math isgreater()用法及代碼示例
- C++ Math fabs()用法及代碼示例
- C++ Math islessgreater()用法及代碼示例
- C++ Math log2()用法及代碼示例
- C++ Math nearbyint()用法及代碼示例
- C++ Math tan()用法及代碼示例
- C++ Math log()用法及代碼示例
- C++ Math nextafter()用法及代碼示例
- C++ Math fdim()用法及代碼示例
- C++ Math isfinite()用法及代碼示例
- C++ Math erfc()用法及代碼示例
- C++ Math sinh()用法及代碼示例
- C++ Math scalbln()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Math ceil()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。