Easy Tutorial
❮ C Function Mbstowcs C Function Strlen ❯

C Exercise Example 20 - Free Fall of a Ball

C Language Classic 100 Examples

Question: A ball is dropped from a height of 100 meters freely, and after each landing, it bounces back to half of its original height; then it falls again. Calculate the total distance it has traveled by the 10th landing and how high it bounces on the 10th rebound.

Program Analysis: See the comments below.

Program Source Code:

Example

//  Created by www.tutorialpro.org on 15/11/9.
//  Copyright © 2015 tutorialpro.org. All rights reserved.
//

#include<stdio.h>
int main()
{
    float h,s;
    h=s=100;
    h=h/2; // Height of the first rebound
    for(int i=2;i<=10;i++)
    {
        s=s+2*h;
        h=h/2;
    }
    printf("By the 10th landing, it has traveled %f meters, and the 10th rebound height is %f meters\n",s,h);
    return 0;
}

The output of the above example is:

By the 10th landing, it has traveled 299.609375 meters, and the 10th rebound height is 0.097656 meters

C Language Classic 100 Examples

❮ C Function Mbstowcs C Function Strlen ❯