c++编程中ceil与#include <cmath>如何使用?
展开全部
ceil 的函数原型是 double ceil (double x); 头文件#include <cmath>
求一个数的天花板值。 即 取整运算,得到 大于等于 x 的最小整数。
例如:
#include<iostream>
using namespace std;
#include <cmath>
#include <stdio.h> /* printf */
intmain ()
{
printf ("ceil of 2.3 is %.1f\n", ceil(2.3) );
printf ("ceil of 3.8 is %.1f\n", ceil(3.8) );
printf ("ceil of -2.3 is %.1f\n", ceil(-2.3) );
printf ("ceil of -3.8 is %.1f\n", ceil(-3.8) );
return0;
}
输出:
ceil of 2.3 is 3.0
ceil of 3.8 is 4.0
ceil of -2.3 is -2.0
ceil of -3.8 is -3.0
求一个数的天花板值。 即 取整运算,得到 大于等于 x 的最小整数。
例如:
#include<iostream>
using namespace std;
#include <cmath>
#include <stdio.h> /* printf */
intmain ()
{
printf ("ceil of 2.3 is %.1f\n", ceil(2.3) );
printf ("ceil of 3.8 is %.1f\n", ceil(3.8) );
printf ("ceil of -2.3 is %.1f\n", ceil(-2.3) );
printf ("ceil of -3.8 is %.1f\n", ceil(-3.8) );
return0;
}
输出:
ceil of 2.3 is 3.0
ceil of 3.8 is 4.0
ceil of -2.3 is -2.0
ceil of -3.8 is -3.0
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询