习题4-8 高空坠球
1 #include<stdio.h> 2 3 int main(void) 4 { 5 int height, n; 6 double sum, h; 7 8 scanf_s("%d %d", &height, &n); 9 10 for (int i = 0; i <= n; i++) 11 { 12 if (i == 0) 13 { 14 sum = 0; 15 h = 0; 16 } 17 18 if (i == 1) 19 { 20 sum = height; 21 h = height / 2.0; 22 } 23 24 if (i > 1) 25 { 26 sum = sum + h * 2; 27 h = h / 2; 28 } 29 } 30 31 printf("%.1f %.1f\n", sum, h); 32 33 return 0; 34 }