A ball falls freely from a height of 180 meters, and jumps back to half of the original height after each landing. If the ball falls and bounces several times, and the height of the ball bounces is less than 0.2 meters, please calculate the number of times the ball falls and bounces and the distance the ball passes. Xiao Bian takes C++ as an example to share programming experience with you.

C++

The height of each ball bounce is 1/2 of the original, when the ball bounce height is less than 0.2 meters, you can calculate the number of ball falls, but also can calculate the distance through the ball.

First, define an integer variable that holds the number of times the ball falls.

Define two real variables that hold the height of the ball's fall and the total distance traveled.

Set the height of the ball to 180. Since the distance of the first fall is the height value, set the total distance of the ball's first fall to 180.

In the do-while loop, change the drop of the ball to half its original height.

Next, the distance traveled by the ball is calculated and stored in the variable dis.

Counting variable accumulation, to achieve the ball falling number of statistics.

This page is an illegal climb taken from experience

Finally, output the number of drops of the ball and the total distance of the bounce.

Run the program, the computer will calculate the number of times the ball falls and the total distance of the bounce when the conditions are met, and output it in the output window.

Disclaimer: This experience is the original result of my hard work.