精品偷拍一区二区三区,亚洲精品永久 码,亚洲综合日韩精品欧美国产,亚洲国产日韩a在线亚洲

  • <center id="usuqs"></center>
  • 
    
  • C#兩個很簡單的編程問題一球從100米高度自由落下

    C#兩個很簡單的編程問題一球從100米高度自由落下
    1.一球從100米高度自由落下,每次落地后反跳回原高度的一半,再落下,求它在第10次落地時,共經(jīng)過多少米?第10次反彈的高度是多少?
    2.輸入10個整數(shù),統(tǒng)計并輸出其中正數(shù)、負數(shù)和零的個數(shù).
    用C#語言編程,
    其他人氣:129 ℃時間:2020-06-20 08:15:32
    優(yōu)質(zhì)解答

    第一題

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace IronBall
    {
        public class IronBall
        {
            public double hight=0;
    //h是高度,count是反彈次數(shù)
            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("\n正分:" + ps1.plusZero());
                Console.WriteLine("\n負分數(shù):" + ps1.minusZero());
                Console.WriteLine("\n零分:" + ps1.zero());
                Console.ReadLine();
            }
        }
    }
    我來回答
    類似推薦
    請使用1024x768 IE6.0或更高版本瀏覽器瀏覽本站點,以保證最佳閱讀效果。本頁提供作業(yè)小助手,一起搜作業(yè)以及作業(yè)好幫手最新版!
    版權(quán)所有 CopyRight © 2012-2024 作業(yè)小助手 All Rights Reserved. 手機版