一球從100米高度自由落下,每次落地後反跳回原高度的一半
再落下,求它在第n次落地時,共經過多少米?第n次反彈多高?
/* * File Name: bounce_half.c * Author: MH * Since 2011/03/08 * Toolkit: Dev C++ */ # include <stdlib.h> # include <stdio.h> int main(){ int n; float path, hight=100.0;; printf("How many times does the ball bounce?\nPlease input a integer : "); scanf("%d", &n); path = hight; hight = hight/2; for(i=2; i<=n; i++){ // 因為第一次不算,所以i從2開始 path = path + hight*2; // 計算總路徑 hight = hight/2; // 每彈跳一次,高度會減半 } printf("\nThe total path = %f(m)\nThe final hight = %f(m)\n\n", path, hight); system("Pause"); return 0; }
沒有留言:
張貼留言