📄 class1.cs
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -