ylbtech-Arithmetic:Console-算法[for,if]-一 一球從100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地時,共經過多少米?第10次反彈多高? |
一球從100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在
第10次落地時,共經過多少米?第10次反彈多高?
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
請按任意鍵繼續. . .