<2> 一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?

分析:

指尖上的代码[C语言版]-<2>

代码:

#include "Stdio.h"
#include "Conio.h"
#include "Math.h"

int main(void)
{
  /* init_h表示初始高度  sum用来记录球所经过的距离  h表示球反弹后的距离*/
  float init_h=100,sum=0.0,h;
  /* n表示球第n次着地*/
  int n;
  for(n=1;n<=10;n++)
     {

       if(n==1)
         {
           sum=100.0;
         }
       else
         {
            sum=sum+2*h;
         }
       h=init_h/(pow(2,n));
     }
  printf("The distance of the ball run is %fm.\n\n",sum);
  printf("Tenth ball where the height is %fm.",h);
  return 0;
}

编译结果:

指尖上的代码[C语言版]-<2>

点石成金  写于  2012/08/07/14:21

相关文章:

  • 2021-09-19
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2021-08-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
  • 2022-12-23
相关资源
相似解决方案