C#两个很简单的编程问题一球从100米高度自由落下

C#两个很简单的编程问题一球从100米高度自由落下

题目
C#两个很简单的编程问题一球从100米高度自由落下
1.一球从100米高度自由落下,每次落地后反跳回原高度的一半,再落下,求它在第10次落地时,共经过多少米?第10次反弹的高度是多少?
2.输入10个整数,统计并输出其中正数、负数和零的个数.
用C#语言编程,
答案

第一题

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;
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(" 正分:" + ps1.plusZero());
            Console.WriteLine(" 负分数:" + ps1.minusZero());
            Console.WriteLine(" 零分:" + ps1.zero());
            Console.ReadLine();
        }
    }
}
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点

超级试练试题库

© 2017-2019 超级试练试题库,All Rights Reserved.