[C / C ++ syntax] - floor function

floor () function

The floor function is a function of rounding down, returns the largest integer less than or equal to x is less than, i.e. the -infinity

Function prototype: double floor (double)

floor function is header <math.h>
For example:

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

int main(void)
{
    double a;
    while(~scanf("%lf", &a))
    {
        double ans1;
        ans1 = floor(a);
        printf("floor = %lf\n", ans1);
    }
    return 0;
}

Here Insert Picture Description

ceil () function

ceil function of rounding up function, returns the largest integer equal to or greater than greater than x, i.e., rounding toward plus infinity

The function prototype: double ceil (double x)

ceil function is header <math.h>
For example:

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

int main(void)
{
    double a;
    while(~scanf("%lf", &a))
    {
        double ans1;
        ans1 = ceil(a);
        printf("ceil= %lf\n", ans1);
    }
    return 0;
}

Here Insert Picture Description

round () function

round () function is a function of rounding

The function prototype: double round (double x)

round () function is header <math.h>
For example:

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

int main(void)
{
    double a;
    while(~scanf("%lf", &a))
    {
        double ans1;
        ans1 = round(a);
        printf("round = %lf\n", ans1);
    }
    return 0;
}

Here Insert Picture Description

to sum up

Function name Function Description 2.9 2.1 -2.9 -2.1
floor() Downward (minus infinity) of the integral function 2.0 2.0 -3.0 -3.0
ceil() Upward (positive infinity) of the integral function 3.0 3.0 -2 -2
round() rounding 3.0 2.0 -3.0 -2.0
Published 20 original articles · won praise 2 · Views 939

Guess you like

Origin blog.csdn.net/zhbbbbbb/article/details/103560842