C# 小球100米自由落下
2021-04-21 23:29
标签:col ++ convert read lin 转化 write oid readline C# 小球100米自由落下 标签:col ++ convert read lin 转化 write oid readline 原文地址:https://www.cnblogs.com/xiaozhushifu/p/8250849.html 1 //一球从N 米高自由落下,每次落地后反跳回原高度的一般;再录下,求它在第十次落地时,共经过多少米?第10次反弹多高
2 static string ballDsitance(float height1, int n)
3 {
4 float sum = height1;
5 float height = height1;
6 for (int i = 1; i )
7 {
8 sum += height;//sum =sum + 2*( heigth/2)
9 height /= 2;
10
11 }
12
13 string str = "总共经过了" + sum + "米,最后反弹高度" + height + "米";
14 return str;
15 }
16
17 static void Main(string[] args)
18 {
19 Console.WriteLine("请输入球的初始高度:");
20 float height = Convert.ToSingle(Console.ReadLine());// 将输入的字符转化为float;
21 Console.WriteLine("请输入球反弹的次数:");
22 int n = Convert.ToInt32(Console.ReadLine());
23 Console.WriteLine(ballDsitance(height, n));
24
25 Console.ReadKey();
26 }
27 }