C Exercise Example 20 - Small ball free fall
100 cases of classic C language
Title: a ball free fall from a height of 100 meters, after each landing anti jump back half its original height; down again, find it at the 10th floor, after a total of how many meters? 10th rebound tall?
Program analysis: See the note below.
Source Code:
// Created by www.w3big.com on 15/11/9. // Copyright © 2015年 本教程. All rights reserved. // #include<stdio.h> int main() { float h,s; h=s=100; h=h/2; //第一次反弹高度 for(int i=2;i<=10;i++) { s=s+2*h; h=h/2; } printf("第10次落地时,共经过%f米,第10次反弹高%f米\n",s,h); return 0; }
The above example output is:
第10次落地时,共经过299.609375米,第10次反弹高0.097656米