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;
}
运行结果: