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

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

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

#include <stdio.h>

int main()
{
    double height = 0.0;
    double temp = 0.0;
    double ret = 0.0;
    int num = 0;
    scanf("%d", &num);
    temp = num;
    height += temp;    //第一次高度
    for(int i = 0; i < 4; i++)
    {
        temp = temp / 2;    //第i次落下的高度
        height += (temp * 2);    //需要考虑弹起的高度
    }
    ret = temp / 2;
    printf("%lf\n", height);
    printf("%lf\n", ret);
    return 0;
}
全部评论

相关推荐

10-10 00:14
门头沟学院 Java
程序员小白条:20年架构师,无工资
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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