题解 | #求小球落地5次后所经历的路程和第5次反弹的高度#

求小球落地5次后所经历的路程和第5次反弹的高度

https://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446

#include <iostream>
using namespace std;

int main() {
    float hight;
    cin >> hight;
    float s = 0;
    for(int i = 0;i < 5;i++){
        s =s+ hight + hight/2;
        hight = hight/2;
    }
    cout << s - hight<< endl;
    cout << hight << endl;
}
// 64 位输出请用 printf("%lld")

不知道为啥是中等题。

用个float解决小数问题就完事了

华为机试刷题记录 文章被收录于专栏

记录一下手打代码的解题思路方便复习

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-10 11:55
点赞 评论 收藏
分享
06-18 13:28
已编辑
门头沟学院 Web前端
爱睡觉的冰箱哥:《给予你300的工资》,阴的没边了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务