C floor 函数

C floor 函数是一个数学函数,它返回不大于给定数字的最大整数。数学 floor 函数的语法如下。

double floor(double number);

floor 函数示例

math floor 函数允许您找到不大于用户给定数字的最大整数。在此程序中,我们将找到相同的数并显示输出,语言为 C Programming

#include <stdio.h>
#include <math.h>

int main()
{
    printf("\n The Floor Value of 0.75    = %.2f ", floor(0.75));
    printf("\n The Floor Value of 12.25   = %.2f ", floor(12.25));    
    printf("\n The Floor Value of 152.50  = %.2f ", floor(152.50));
    
    printf("\n The Floor Value of -12.36  = %.2f ", floor(-12.36)); 
    printf("\n The Floor Value of -27.82  = %.2f ", floor(-27.32));  
    printf("\n The Floor Value of -90.50  = %.2f ", floor(-90.50));
  
    return 0;
}
C Programming math floor Function

在此 程序中,我们使用 math floor 函数来查找用户输入的浮点值的最接近的整数。

#include <stdio.h>
#include <math.h>

int main()
{
float number, fValue;

printf(" Please Enter any Numeric : ");
scanf("%f", &number);

fValue = floor(number);

printf("\n The Result of %.2f = %.4f ", number, fValue);

return 0;
}
 Please Enter any Numeric :  125.87

 The Result of 125.87 = 125.0000