1118 Bounced Ball

Title description

A ball falls freely from a height of 100 meters, and then bounces to half of its original height each time it hits the ground before falling. Find out how many meters it has traveled for the nth landing and the height of the nth bounce.

Input requirements

Enter a positive integer n.

Output requirements

The total distance traveled by the nth landing and the height of the nth bounce are output in turn (retaining 6 decimal places), separated by a space.

Input sample

10

Sample output

299.609375 0.097656

Reference program

#include<stdio.h>

int main()
{
    double sum=0,high=100;
    int n,i;

    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        sum += high;
        high /= 2;
        sum += high;
    }
    sum -= high;
    printf("%.6lf %.6lf\n",sum,high);
    return 0;
}

 

Guess you like

Origin blog.csdn.net/weixin_44643510/article/details/113925222