ceil(),floor(),round()函数浅析

ceil(),floor(),round()这三个函数都是取整函数
用我自己的话来讲:
ceil是顺着X轴的正半轴向最大的整数取值。
floor是顺着X轴的负半轴向小的整数取值。
round通俗来讲就是4舍5入的方式。
这几个函数的头文件都是#include
代码如下:

#include<cstdio>
#include<iostream>
#include<functional>
#include<algorithm>
#include<cmath>
#include<math.h>
using namespace std;
int main()
{
    
    
    double x;
    int t;
    cin>>x;
    t=ceil(x);
    cout<<t<<endl;;
    t=floor(x);
    cout<<t<<endl;
    t=round(x);
    cout<<t<<endl;;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/malloch/article/details/106307674