method

1397Currently online
8Today's Reading
30Share Today
Multilingual display

How to calculate the number of drops and the total distance of a ball in free fall

2018-05-02 03:12:00

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.

Tools/Materials

C++

Methods/Steps
1

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.

2

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

3

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

4

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.

5

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

6

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

7

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

8

This page is an illegal climb taken from experience

9

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

10

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.

Matters needing attention

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

Recommendation