var amount = 0.0d;
            var hitTheTargetCount = 0.0d;
            var M = 2.0d;
            var rnd=new Random();
            for (int i = 0; i < 1000; i++)
            {
                var x = rnd.NextDouble() * Math.PI;
                var y = rnd.NextDouble() * M;
                //Console.WriteLine("x:{0},y:{1}", x, y);
                if (y <= Math.Sin(x))
                {
                    hitTheTargetCount++;
                }
                amount++;
            }

            var s = (hitTheTargetCount / amount) * M * Math.PI;
            Console.WriteLine(s);
View Code

相关文章:

  • 2021-08-09
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2021-10-03
猜你喜欢
  • 2022-03-05
  • 2021-09-11
  • 2019-09-12
  • 2022-01-08
  • 2021-05-19
  • 2021-09-09
  • 2021-12-18
相关资源
相似解决方案