HJ38 finds the distance traveled by the ball after 5 times and the height of the fifth bounce

 Medium questions, examining thinking, the main mathematical problems, are not difficult, of course, the optimal solution is the best. At present, we should first seek to write correctly, and then pursue optimization in the future.

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    double height=n;
    double sum=height;
    for(int i=2;i<6;i++)
    {
        height=height/2;
        sum+=2*height;
    }
    cout<<sum<<endl;
    cout<<height/2;
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324163078&siteId=291194637