早教吧作业答案频道 -->其他-->
C#两个很简单的编程问题一球从100米高度自由落下1.一球从100米高度自由落下,每次落地后反跳回原高度的一半,再落下,求它在第10次落地时,共经过多少米?第10次反弹的高度是多少?2.输入10个整
题目详情
C#两个很简单的编程问题一球从100米高度自由落下
1.一球从100米高度自由落下,每次落地后反跳回原高度的一半,再落下,求它在第10次落地时,共经过多少米?第10次反弹的高度是多少?
2.输入10个整数,统计并输出其中正数、负数和零的个数.
用C#语言编程,
1.一球从100米高度自由落下,每次落地后反跳回原高度的一半,再落下,求它在第10次落地时,共经过多少米?第10次反弹的高度是多少?
2.输入10个整数,统计并输出其中正数、负数和零的个数.
用C#语言编程,
▼优质解答
答案和解析
using System.Collections.Generic;
using System.Text;
namespace IronBall
{
public class IronBall
{
public double hight=0;
//h是高度,count是反弹次数
public double getDistance(double h,int count)
{
double dis = h;
this.hight = h;
for (int i = 0; i < count-1; i++)
{
hight = hight / 2;
dis += 2*hight;
}
return dis;
}
}
class Program
{
static void Main(string[] args)
{
IronBall rb = new IronBall();
Console.WriteLine("总距离"+rb.getDistance(100,10));
Console.WriteLine("最后一次反弹高度" +rb.hight/2);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
public class PointsStat
{
ArrayList points = new ArrayList();
public void addPoint(double p)
{
points.Add(p);
}
public int plusZero()
{
int count = 0;
foreach (double p in points)
{
if (p > 0)
count++;
}
return count;
}
public int minusZero()
{
int count = 0;
foreach (double p in points)
{
if (p < 0)
count++;
}
return count;
}
public int zero()
{
int count = 0;
foreach (double p in points)
{
if (p==0)
count++;
}
return count;
}
}
static void Main(string[] args)
{
PointsStat ps1 = new PointsStat();
for (int i = 0; i < 10;i++ )
{
string s = Console.ReadLine();
if (s != "")
{
double d = double.Parse(s);
ps1.addPoint(d);
}
else
i--;
}
Console.WriteLine("\n正分:" + ps1.plusZero());
Console.WriteLine("\n负分数:" + ps1.minusZero());
Console.WriteLine("\n零分:" + ps1.zero());
Console.ReadLine();
}
}
}
第一题
using System;using System.Collections.Generic;
using System.Text;
namespace IronBall
{
public class IronBall
{
public double hight=0;
//h是高度,count是反弹次数
public double getDistance(double h,int count)
{
double dis = h;
this.hight = h;
for (int i = 0; i < count-1; i++)
{
hight = hight / 2;
dis += 2*hight;
}
return dis;
}
}
class Program
{
static void Main(string[] args)
{
IronBall rb = new IronBall();
Console.WriteLine("总距离"+rb.getDistance(100,10));
Console.WriteLine("最后一次反弹高度" +rb.hight/2);
Console.ReadLine();
}
}
}
第二题:
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
public class PointsStat
{
ArrayList points = new ArrayList();
public void addPoint(double p)
{
points.Add(p);
}
public int plusZero()
{
int count = 0;
foreach (double p in points)
{
if (p > 0)
count++;
}
return count;
}
public int minusZero()
{
int count = 0;
foreach (double p in points)
{
if (p < 0)
count++;
}
return count;
}
public int zero()
{
int count = 0;
foreach (double p in points)
{
if (p==0)
count++;
}
return count;
}
}
static void Main(string[] args)
{
PointsStat ps1 = new PointsStat();
for (int i = 0; i < 10;i++ )
{
string s = Console.ReadLine();
if (s != "")
{
double d = double.Parse(s);
ps1.addPoint(d);
}
else
i--;
}
Console.WriteLine("\n正分:" + ps1.plusZero());
Console.WriteLine("\n负分数:" + ps1.minusZero());
Console.WriteLine("\n零分:" + ps1.zero());
Console.ReadLine();
}
}
}
看了 C#两个很简单的编程问题一球...的网友还看了以下:
两只相同的鸡蛋,从同样的高度自由下落,第一次落在水泥地板上,鸡蛋被摔破了;第二次落在海绵%2两只相同 2020-03-30 …
求物理高手做道关于自由落体的题菜鸟勿看!从一定高度的气球上自由落下两个物体,第一个物体下落1s后, 2020-04-26 …
一个质量为m=0.2kg的小球从1.25m的高处自由下落,落到一块厚软垫上,若小球从接触软垫到落至 2020-05-13 …
一道自由落体问题从静止在一定高度的气球上自由落下两个物体,第一个物体下落1秒后,第二个物体开始下落 2020-05-13 …
物理自由落体一根3m长绳子两端各系一块石头,拿着上端的石头站在桥上并使石头与桥面相平,另一端自然下 2020-05-17 …
一只球从高处自由下落,下级0.5s时,一颗子弹从球开始下落的位置向下射击,要使球在下落1.8s时被 2020-05-23 …
三个射手射敌机射中几率0.40.60.7如果一人射中敌机被击落概率0.2两人射中击落概率0.6如果 2020-06-16 …
1.已知方程x^2-(m+1)x+4=0的两根都落在0,3,求m的取值范围2.求m的取值范围,使关 2020-06-27 …
物体在受到加速度不变的情况下,一段路程的平均速度怎么求?例,一物体在地表附近自由落体,在两秒后,它 2020-07-19 …
这两个圆圈里数字的和是多少?电子跳蚤每跳一步,可以从一个圆圈跳到相邻的圆圈,现一个红跳蚤从标有“0” 2020-11-03 …