取整函数
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
如: 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; }
相关文章推荐
- 小圆点的绘制
- Linux vi 操作笔记
- HashCode详解
- Use of the MANIFEST.MF file in Java
- awk内建变量示例详解之NR、FNR、NF
- (四)5多处理器下的竞态和并发
- BZOJ 1491 社交网络
- 网络虚拟化-简介
- ID3
- hrbust 1662 凸多边形【最短路SPFA+建图+思维】好题
- 百度笔试-房屋群
- Docker-搭建简单的应用栈
- 无限轮播加小圆点
- 【经典算法探究】:B树,B+树,B-树,B*树
- LeetCode 172. Factorial Trailing Zeroes题解
- http协议没有已注册的程序
- PHP学习笔记:用mysqli连接数据库
- yii2自定义500错误
- 模板方法模式
- 字节流转化为字符流输出