floor(x)向下取整,返回一个<=x的int整型。
ceil(x)向上取整,返回一个>=x的int整型。
头文件是<cmath>或<math.h>
<pre name="code" class="cpp">#include "stdafx.h"
#include<iostream>
#include<cmath>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << floor(4)<<endl;
cout << floor(4.9)<<endl;
cout << ceil(4.111) << endl;
cout << ceil(4.9) << endl;
system("pause");
return 0;
}运行结果:
本文介绍C++中floor与ceil函数的基本用法,包括如何进行向上和向下取整操作。这两个函数分别用于获取小于等于指定数值的最大整数和大于等于指定数值的最小整数。
1万+

被折叠的 条评论
为什么被折叠?



