C语言中有没有FLOOR函数
答案:3 悬赏:60 手机版
解决时间 2021-03-17 15:37
- 提问者网友:相思似海深
- 2021-03-16 18:17
C语言中有没有FLOOR函数
最佳答案
- 五星知识达人网友:像个废品
- 2021-03-16 19:03
c语言标准库中有名为floor的函数。
函数的声明
double floor(double x)
参数: x-- 这是浮点类型的值
返回值: 返回小于或等于x的最大整数值
使用floor函数需要额外包含#include头文件
示例
#include
#include
int main ()
{
float val1, val2, val3, val4;
val1 = 1.6;
val2 = 1.2;
val3 = 2.8;
val4 = 2.3;
printf("Value1 = %.1lf\n", floor(val1));
printf("Value2 = %.1lf\n", floor(val2));
printf("Value3 = %.1lf\n", floor(val3));
printf("Value4 = %.1lf\n", floor(val4));
return(0);
}
运行将产生以下结果:
Value1 = 1.0
Value2 = 1.0
Value3 = 2.0
Value4 = 2.0
函数的声明
double floor(double x)
参数: x-- 这是浮点类型的值
返回值: 返回小于或等于x的最大整数值
使用floor函数需要额外包含#include
示例
#include
#include
int main ()
{
float val1, val2, val3, val4;
val1 = 1.6;
val2 = 1.2;
val3 = 2.8;
val4 = 2.3;
printf("Value1 = %.1lf\n", floor(val1));
printf("Value2 = %.1lf\n", floor(val2));
printf("Value3 = %.1lf\n", floor(val3));
printf("Value4 = %.1lf\n", floor(val4));
return(0);
}
运行将产生以下结果:
Value1 = 1.0
Value2 = 1.0
Value3 = 2.0
Value4 = 2.0
全部回答
- 1楼网友:北城痞子
- 2021-03-16 20:46
有啊!浮点型
- 2楼网友:举杯邀酒敬孤独
- 2021-03-16 19:30
#include
#include
void main( void )
{
double y;
y = floor( 2.8 );
printf( "The floor of 2.8 is %f\n", y );
y = floor( -2.8 );
printf( "The floor of -2.8 is %f\n", y );
y = ceil( 2.8 );
printf( "The ceil of 2.8 is %f\n", y );
y = ceil( -2.8 );
printf( "The ceil of -2.8 is %f\n", y );
}
Output
The floor of 2.8 is 2.000000
The floor of -2.8 is -3.000000
The ceil of 2.8 is 3.000000
The ceil of -2.8 is -2.000000
#include
void main( void )
{
double y;
y = floor( 2.8 );
printf( "The floor of 2.8 is %f\n", y );
y = floor( -2.8 );
printf( "The floor of -2.8 is %f\n", y );
y = ceil( 2.8 );
printf( "The ceil of 2.8 is %f\n", y );
y = ceil( -2.8 );
printf( "The ceil of -2.8 is %f\n", y );
}
Output
The floor of 2.8 is 2.000000
The floor of -2.8 is -3.000000
The ceil of 2.8 is 3.000000
The ceil of -2.8 is -2.000000
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯