C语言中几个常用数学计算函数ceil(), floor(), round()的用法
2017-12-19 15:02
801 查看
最近在实现算法的过程中,遇到了使用几个数学计算函数,感觉挺有意思,就记下来
方便以后使用。
ceil(x)返回不小于x的最小整数值(然后转换为double型)。
floor(x)返回不大于x的最大整数值。
round(x)返回x的四舍五入整数值。
代码:
运行结果:
方便以后使用。
ceil(x)返回不小于x的最小整数值(然后转换为double型)。
floor(x)返回不大于x的最大整数值。
round(x)返回x的四舍五入整数值。
代码:
#include <stdio.h> #include <math.h> int main(int argc, const char *argv[]) { float num = 1.4999; printf("ceil(%f) is %f\n", num, ceil(num)); printf("floor(%f) is %f\n", num, floor(num)); printf("round(%f) is %f\n", num, round(num)); return 0; }
运行结果:
ceil(1.499900) is 2.000000 floor(1.499900) is 1.000000 round(1.499900) is 1.000000
相关文章推荐
- Delphi 常用函数(数学函数)round、trunc、ceil和floor
- delphi 常用函数(数学函数)round、trunc、ceil和floor
- mysql数学函数之ceil,floor用法
- 数学函数ceil(), floor(), round()备忘
- C语言常用数学函数及其用法
- C语言常用数学函数及其用法
- C/C++ 数学函数 ceil(), floor(), round()
- Javascript Math 中常用函数<一>--ceil(),floor(),round()
- 经常用到取整的函数,今天小小的总结一下!其实很简单,就是几个函数而已~~主要是:ceil,floor,round,intval
- C语言常用数学函数及其用法
- JS中4种数学函数:ceil, floor, round; random
- C语言常用数学函数及其用法
- Javascript Math ceil()、floor()、round()三个函数的区别
- c语言之开发中常用的几个函数(一)
- sql 之 round(),trunc(),floor(),ceil()函数
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- javascript中的Math.round()和Math.floor()函数Math.ceil()的区别
- Javascript Math ceil()、floor()、round()三个函数的区别
- C语言几个函数用法小结
- Javascript Math ceil()、floor()、round()三个函数的区别