using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace montekarlo { internal class MonteKarlo { public static void MonteKarloP() { int n = 1000; int k = 0; double S; Random rand = new Random(); for (int i = 1; i < n; i++) { double x = rand.NextDouble(); double y = rand.NextDouble(); if (x * x + y * y <= 1) { k++; } } S = 4.0 * k / n; Console.WriteLine("Результат Pi = " + S); Console.WriteLine("Точно Pi = " + Math.PI); } } }