题解 | #求小球落地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]); } }