A ball falls freely from a height of 100 meters, rebounds back to half of its original height each time it hits the ground, and then falls again;

How many meters did it pass when it landed on the 10th time? How high was the 10th rebound?

#include <stdio.h>

void process(double h, int t)
{
    
    
  double H = h; //将原始高度保留
  int T = t;
  double sum = 0;
  while (t > 0)
  {
    
    
    // 1、2、3、4...
    //100、50、25、12.5
    sum = sum + h; //每次落地前高度之和。
    h = h / 2;
    t--;
  }
  printf("第%d次下落共经过:%lf米\n", T, 2 * sum - H); //除第一次以外每一次都是先弹起,再下落
  printf("第%d次反弹的高度是:%lf米\n", T, h);
}

int main()
{
    
    
  int hight = 100;
  int times = 10;
  process(hight, times);
  return 0;
}

operation result
Insert picture description here

Guess you like

Origin blog.csdn.net/and_what_not/article/details/113831572