/*小球从100米落下,每次落地后反跳会原高的一半。求他在
第十次落地时,共经过多少米。
*/
用递归求
假设第十次不在反弹
#include <stdio.h>
/*小球从100米落下,每次落地后反跳会原高的一半。求他在
第十次落地时,共经过多少米。
*/
double sum(double h,int c);
int main (int argc, char* argv[])
{
double h;
int m,n,c;
int g,s,b,i,j,q;
printf("The fight h.\n");
scanf("%lf",&h);
printf("The length is %.4lf\n", sum(h,0));
}
double sum(double h, int c)
{
c++;
if (c == 10)
return 0;
return h +(h/2) + sum((h / 2),c);
}