数学函数:ceil(), floor(), round()的用法
最近在实现算法的过程中,遇到了使用几个数学计算函数,感觉挺有意思,就记下来
方便以后使用。
ceil(x)返回不小于x的最小整数值。
floor(x)返回不大于x的最大整数值。
round(x)返回x的四舍五入整数值。
代码:
1 #include <stdio.h> 2 #include <math.h> 3 int main(int argc, const char *argv[]) 4 { 5 float num = 1.4999; 6 printf("ceil(%f) is %f\n", num, ceil(num)); 7 printf("floor(%f) is %f\n", num, floor(num)); 8 printf("round(%f) is %f\n", num, round(num)); 9 return 0; 10 }
运行结果:
1 ceil(1.499900) is 2.000000 2 floor(1.499900) is 1.000000 3 round(1.499900) is 1.000000
转载于:https://www.cnblogs.com/dylancao/p/8065732.html
作者QQ4577105