1234567891011121314151617181920212223242526272829303132333435 |
- 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);
- }
- }
- }
|