c#求圆周率问题
昨天看到用c++实现的求圆周率的代码,自己就想用c#写个小程序,可是求随机数这块有问题,到这就不知道该怎么改了,麻烦大家帮看看应该怎么写这个代码,我的代码如下[code=csharp static void Main(string[] args)
{
double j, k, x, y,p,t;
int m = 0;
Console.WriteLine("请输入实验次数:");
string str = Console.ReadLine();
int n = Convert.ToInt32(str);
Random rand = new Random();
for (int i = 0; i <= n; i++)
{
int number = rand.Next(2);
j = 20000*number;
k = 20000*number;
x = j/10000.0;
y = k/10000.0;
if ((x-1)*(x-1) + (y-1)*(y-1) <= 1)
{
m++;
}
Console.WriteLine("x={0},y={1}",x,y);
}
p = m/n;
t = 4 * p;
Console.WriteLine("落在圆区域的次数:"+m);
Console.WriteLine("随机点落在圆区域的概率:"+p);
Console.WriteLine("π的值为:"+t);
Console.ReadLine();
}][/code]