1 条题解
-
1
取整小帮手 题解
题目要求:输入一个小数 x,依次输出向下取整、向上取整、四舍五入的结果,各占一行。
所需知识点:
- 数学库(floor¹,ceil²,round³)
- 输出(cout)
完整代码;
#include<iostream> #include<cmath> using namespace std; double x; int main(){ cin >> x; cout << floor(x) << endl; // floor是数学库中向下取整的函数 cout << ceil(x) << endl; // ceil 是数学库中向上取整的函数 cout << round(x); // round是数学库中四舍五入的函数 }(1)floor floor:向下取整,取不大于 x 的最大整数(如 2.7→2,-2.3→-3)。
(2)ceil ceil:向上取整,取不小于 x 的最小整数(如 2.3→3,-2.7→-2)。
(3)round round:四舍五入,按远离零方向舍入到最接近的整数(如 2.5→3,-2.5→-3)。
制作不易点个赞吧 Q w Q meow~
- 1
信息
- ID
- 62
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 11
- 已通过
- 4
- 上传者