C++中的CELL和LASE函数

在数学和计算机科学中,下限函数和上限函数分别将实数映射到前面最大的整数或后面最小的整数。

null

楼层(x): 返回小于或等于x的最大整数(即:舍入最接近的整数)。

// Here x is the floating point value.
// Returns the largest integer smaller 
// than or equal to x 
double floor(double x)  

地板的示例:

Input : 2.5
Output : 2

Input : -2.1
Output : -3

Input : 2.9
Output : 2

// C++ program to demonstrate floor function
#include <iostream>
#include <cmath>
using namespace std;
// Driver function
int main()
{
// using floor function which return
// floor of input value
cout << "Floor is : " << floor (2.3) << endl;
cout << "Floor is : " << floor (-2.3) << endl;
return 0;
}


输出:

Floor is : 2
Floor is : -3

ceil(x): 返回大于或等于x的最小整数(即:四舍五入最接近的整数)。

// Here x is the floating point value.
// Returns the smallest integer greater 
// than or equal to x 
double ceiling(double x)  

Ceil的例子:

Input : 2.5
Output : 3

Input : -2.1
Output : -2

Input : 2.9
Output : 3

// C++ program to demonstrate ceil function
#include <iostream>
#include <cmath>
using namespace std;
// Driver function
int main()
{
// using ceil function which return
// floor of input value
cout << " Ceil is : " << ceil (2.3) << endl;
cout << " Ceil is : " << ceil (-2.3) << endl;
return 0;
}


Ceil is : 3
Ceil is : -2

本文由 萨希尔·拉吉普特 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享