C++函数整理

该篇博文主要是为了记录啃代码过程中遇到的函数,记录稿,逐步完善。

1.floor函数

功能:把一个小数向下取整
      即就是如果数是2.2 ,那向下取整的结果就为2.000000
原型:double floor(doube x);
    参数解释:
        x:是需要计算的数
返回值:
    成功:返回一个double类型的数,此数默认有6位小数
    无失败的返回值
头文件:#include<math.h>

示例

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    double i = floor(2.2);
    double j = floor(-2.2);
    cout << "The floor of 2.2 is " << i << endl;
    cout << "The floor of -2.2 is " << j << endl;
    system("pause");
    return 0;
}

运行结果:
在这里插入图片描述

2.ceil函数

功能:把一个小数向上取整
      即就是如果数是2.2 ,那向上取整的结果就为3.000000
原型:double ceil(doube x);
    参数解释:
        x:是需要计算的数
返回值:
    成功:返回一个double类型的数,此数默认有6位小数
    无失败的返回值
头文件:#include<math.h>

示例:

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    double i = ceil(2.2);
    double j = ceil(-2.2);
    cout << "The ceil of 2.2 is " << i << endl;
    cout << "The ceil of -2.2 is " << j << endl;
    system("pause");
    return 0;
}

运行结果:
在这里插入图片描述

3.round函数

功能:把一个小数四舍五入
      即就是如果数是2.2 ,那四舍五入的结果就为2
           如果数是2.5,那结果就是3
原型:double round(doube x);
    参数解释:
        x:是需要计算的数
头文件:#include<math.h>

示例:

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    double i = round(2.2);
    double x = round(2.7);
    double j = round(-2.2);
    double y = round(-2.7);
    cout << "The round of 2.2 is " << i << endl;
    cout << "The round of 2.7 is " << x << endl;
    cout << "The round of -2.2 is " << j << endl;
    cout << "The round of -2.7 is " << y << endl;
    system("pause");
    return 0;
}

运行结果:
在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值