Huawei tried to find the distance and the height of 5th rebound after the ball was launched 5 times.

Source: Internet
Author: User

Assume that a ball falls freely from any height. After each landing, it jumps back to half of the original height. Then, how many meters does it experience when it lands for 5th times? How high is the rebound of 5th times?

Input start height, int type

How many meters and how high the rebound is when the output reaches the ground for 5th times?

[Remove invalid 0 at the end of the decimal number]

Sample input: 1

Sample output: 2.875

0.03125

# Include <iostream> using namespace STD; double high (double H, int N); double total (double H, int N); int main () {int height; double total; cin> height; double fif; Total = total (height, 5); fif = high (height, 5); cout <total <Endl; cout <fif; return 0;} double high (double H, int N) {If (n = 1) return H/2; elsereturn high (H/2, N-1 );} double total (double H, int N) {If (n = 1) return h; else return 2 * high (H, N-1) + total (H, N-1 );}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.