个人答案:
#include <iostream>
using namespace std;
int main()
{
float height = 100, sum = 0;
int i;
for (i = 1; i <= 10; i++)
{
height = height / 2; //每次下落反弹回原高度的一半
sum = sum + 2 * height; //弹起来,落下去,故高度要*2
}
sum = sum + 100; //需要加上开始的100米
cout<<"第十次落地共经历了"<<sum<<"米"<<'\n'; //输出总距离
cout << "第十次反弹的高度为:" << height << endl; //输出第十次高度
return 0;
}
结果:
参考答案:
#include <iostream>
using namespace std;
int main()
{
double i,a=100,b=0,n,sum=100;
cout<<"请输入落地次数n:"<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
sum=sum+2*b;
a=a/2;
b=a;
}
cout<<"小球从100m高处落地"<<n<<"次时,共经过"<<sum<<"米.第"<<n<<"次落地后反弹的高度为:"<<b<<"米"<<endl;
system("pause");
return 0;
}