天天看點

自由落體

題目描述

上機練習4.2.3 小球從100高處自由落下,着地後又彈回高度的一半再落下。求第10次着地時, 小球共通過多少路程?

輸入

無輸入。

輸出

小球通過的路程,保留2位小數。

#include<bits/stdc++.h>
using namespace std;
double s,n=100;
int main()
{
    for(int i=1;i<=10;i++)
    {
        s+=n;
        n/=2;
        s+=n;   
    }
    s-=n;
    cout<<fixed<<setprecision(2)<<s;
    return 0;
}