04.floor函数取整时的注意点

RT 传送门

如下代码,我在编译器上测试答案没错,可一递交结果为wa

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int R,Y;
    double M;
    cin>>R>>M>>Y;
    double r = R*0.01 + 1;
    for(int i = 0; i < Y; i++){
        M *= r;
    }
    cout<<floor(M);
}

于是,我去看了floor函数,它是一个double类型的函数,而题目要求结果为整形,此时进行一个强制类型变换即可ac.

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int R,Y;
    double M;
    cin>>R>>M>>Y;
    double r = R*0.01 + 1;
    for(int i = 0; i < Y; i++){
        M *= r;
    }
    cout<<(int)floor(M);
}

总结:当调用函数时,需注意函数的类型,如此题,floor函数为double类型,答案要整形

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值