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

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

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

#include <stdio.h>

int main() {
    int n;
    while(scanf("%d", &n) != EOF) {
        float distance[6];
        distance[0] = n;
        float total = distance[0];
        for(int i = 1; i <= 5; i++) {
            distance[i] = distance[i - 1] / 2;
            if(i != 5){
                total += distance[i]*2;
            }


            // printf("the %d time, total is %f\n", i, total);
        }
        printf("%.3f\n", total);
        printf("%.5f\n", distance[5]);
    }

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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