C# :: Aufgabe #183 :: Lösung #3
4 Lösungen
#183
Funktion um Pi zu berechnen.
Anfänger - C#
von Felix
- 09.07.2017 um 21:59 Uhr
Schreibe eine Methode um Pi zu berechnen. Versuche Pi auf so viele Stellen wie möglich zu berechnen.
#3
von t.wi (660 Punkte)
- 26.06.2019 um 12:06 Uhr
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace pi
{
class Program
{
static void Main(string[] args)
{
Random zufall = new Random();
double innerhlab = 0;
int tropfen = Convert.ToInt32(Console.ReadLine());
for(int i = 0; i <= tropfen;i++)
{
double x = zufall.NextDouble();
double y = zufall.NextDouble();
if(x*x+y*y < 1.0)
{
innerhlab++;
}
}
double pi = 4*innerhlab / tropfen;
Console.WriteLine(pi);
Console.Read();
}
}
}Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1
