#include <stdio.h>
float s_n(float h,const int n,float s)//定義n次共經過多少米函數
{
int i=0;
while(i<n)
{
s=s+h;
h=h/2;
i++;
}
return s;
}
float last_h(float h,const int n)//定義第n次反彈多高函數
{
int i=0;
while(i<n)
{
h=h/2;
i++;
}
return h;
}
int main()
{
float s=0.0;
int n=0;
float hn=0.0;
float h=100.0;
printf("請輸入第幾次:");
scanf("%d",&n);
hn=last_h(h,n);
s=s_n(h,n,s);
printf("hn=%f\n",hn);
printf("s=%f\n",s);
return 0;
}