标签:flow 1.3 div art 注意 otto -- 输出 c++
一球从某一高度落下(整数,单位米),每次落地后反跳回原来高度的一半。再落下。
编程计算气球在第10次落地时,共经过多少米? 第10次反弹多高?
注意:结果可能是实数,结果用double类型保存。
提示:输出时不须要对精度特殊控制,用cout << ANSWER,或者printf("%g", ANSWER)就可以。
20
59.9219 0.0195313
#include<iostream>
using namespace std;
double J(int n,double h)
{
if(n==1)
{
return h;
}
return h+J(n-1,h/2);
}
double JJ(int n,double h)
{
if(n==1)
{
return h/2;
}
return JJ(n-1,h/2);
}
int main()
{
double h;
cin>>h;
cout<<J(10,h)*2-h<<endl;
cout<<JJ(10,h)<<endl;
return 0;
}OpenJudge百炼习题解答(C++)--题3142:球弹跳高度的计算
标签:flow 1.3 div art 注意 otto -- 输出 c++
原文地址:http://www.cnblogs.com/yfceshi/p/7183845.html