| ylbtech-Arithmetic:Console-算法[for,if]-一 一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高? |
| 1.A,Demo(案例) |
一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在
第10次落地时,共经过多少米?第10次反弹多高?
| 1.B,Solution(解决方案) |
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { float sn = 100f; float hn = sn / 2; for (int n = 2; n <= 10; n++) { sn = sn + 2 * hn; //第n次落地时共经过的米数 hn = hn / 2; //第n次反跳高度 } Console.WriteLine("The total of road is {0}",sn); Console.WriteLine("The tenth is {0} meter",hn); } } }
| 1.C,Execution Result(运行结果) |
The total of road is 299.6094 The tenth is 0.09765625 meter 请按任意键继续. . .
本文转自ylbtech博客园博客,原文链接:http://www.cnblogs.com/ylbtech/archive/2013/05/06/3062889.html,如需转载请自行联系原作者
