小编dar*_*ias的帖子

编写自己的数学楼层函数C的实现

我正在考虑floor可用的功能math.h.它很容易使用:

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

int main(void)
{
  for (double a = 12.5; a < 13.4; a += 0.1)
    printf("floor of  %.1lf is  %.1lf\n", a, floor(a));
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我想编写自己的实现怎么办?看起来像这样:

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

double my_floor(double num)
{
    return (int)num;
}

int main(void)
{
    double a;

    for (a = 12.5; a < 13.4; a += 0.1)
        printf("floor of  %.1lf is  %.1lf\n", a, floor(a));

    printf("\n\n");

    for (a = 12.5; a < 13.4; a += 0.1)
        printf("floor of …
Run Code Online (Sandbox Code Playgroud)

c math floor

7
推荐指数
2
解决办法
3236
查看次数

标签 统计

c ×1

floor ×1

math ×1