您的位置:首页 > 其它

取整函数

2016-09-20 19:35 274 查看
用floor函数。floor(x)返回的是小于或等于x的最大整数。

如:     floor(10.5) == 10    floor(-10.5) == -11

使用ceil函数。ceil(x)返回的是大于x的最小整数。

如:     ceil(10.5) == 11    ceil(-10.5) ==-10

   

floor()是向负无穷大舍入,floor(-10.5) == -11;

ceil()是向正无穷大舍入,ceil(-10.5) == -10

 

fix

朝零方向取整,如fix(-1.3)=-1; fix(1.3)=1;

floor

朝负无穷方向取整,如floor(-1.3)=-2; floor(1.3)=1;

ceil

朝正无穷方向取整,如ceil(-1.3)=-1; ceil(1.3)=2;

round

四舍五入到最近的整数,如round(-1.3)=-1;round(-1.52)=-2;round(1.3)=1;round(1.52)=2

题目:http://bak2.vjudge.net/contest/131992#problem

#include<iostream>
#include<cmath>
using namespace std;
#define PI 3.1415926
int main()
{
int n,t=0;
cin>>n;
while(n--)
{
double a,b;
cin>>a>>b;
cout<<"Property "<<++t<<": This property will begin eroding in year "<<ceil(PI*(a*a+b*b)/100.00)<<"."<<endl;}
cout<<"END OF OUTPUT."<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: