⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calcpi.cs

📁 c#的学习资料 书上的东西 很难找到的啊
💻 CS
字号:
//
// CalcPi.cs -- Estimates pi by throwing points into a square. Use to
//              compare execution times.
//
//              Compile this program with the following command line:
//                  C:>csc CalcPi.cs
//
namespace CalcPi
{
    using System;
    class clsMain
    {
        static void Main ()
        {
            const int throws = 10000000;
            DateTime now = DateTime.Now;
            Random rand = new Random ((int) now.Millisecond);
            int Inside = 0;
            for (int i = 0; i < throws; ++i)
            {
                double cx = rand.NextDouble();
                double cy = rand.NextDouble();
                double distance = Math.Sqrt ((cx * cx) + (cy * cy));
                if (distance < 1.0)
                    ++Inside;
            }
            double pi = 4 * (double) Inside / (double) throws;
            DateTime End = DateTime.Now;
            TimeSpan Diff = End - now;
            Console.WriteLine ("pi = " + pi);
            Console.WriteLine ("Milliseconds = " + Diff.TotalMilliseconds);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -