class1.cs
来自「c#的学习资料 书上的东西 很难找到的啊」· CS 代码 · 共 33 行
CS
33 行
using System;
//using System.Threading;
namespace CalcPi
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
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 + =
减小字号Ctrl + -
显示快捷键?