'derWaliser' hinzufügen
parent
2c745fea52
commit
73ff27a03c
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
|
||||
namespace B_GOP01XX_XX2_K03_Aufgabe_1
|
||||
{
|
||||
class WallisschesProdukt
|
||||
{
|
||||
public double berechnePi(int n)
|
||||
{
|
||||
double halfPI = 1.0;
|
||||
double step = 1.0;
|
||||
for (double i = 1; i < Convert.ToDouble(n); i++, step++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
halfPI *= (step / (step + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
halfPI *= ((step + 1) / step);
|
||||
}
|
||||
}
|
||||
return halfPI * 2.0;
|
||||
}
|
||||
}
|
||||
class Helfer
|
||||
{
|
||||
public void zeilenpufferErhoehen()
|
||||
{
|
||||
Console.BufferHeight = 2020;
|
||||
Console.WriteLine("Die \"Pufferhöhe\" der Konsole beträgt nun {0} Zeilen.", Console.BufferHeight);
|
||||
}
|
||||
static int tabellenWeite = 80;
|
||||
|
||||
public void linieAusgeben()
|
||||
{
|
||||
Console.WriteLine(new string('-', tabellenWeite));
|
||||
}
|
||||
}
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
WallisschesProdukt walisschesProdukt = new WallisschesProdukt();
|
||||
Helfer helfer = new Helfer();
|
||||
helfer.zeilenpufferErhoehen();
|
||||
Console.WriteLine(String.Format("{0, 0}{1,-5}{2, 0}{3, 0}", "Faktor:", "", "", "Walissches Produkt:"));
|
||||
for (int i = 1; i <= 1000; i++)
|
||||
{
|
||||
helfer.linieAusgeben();
|
||||
Console.WriteLine(String.Format("|{0, 4}{1, -5}|{2, 5:F15}|"+"{3, -8:F17}|{4, -5}|"+ "", "n=", i, walisschesProdukt.berechnePi(i), Math.Abs((walisschesProdukt.berechnePi(i) - Math.PI)), "Abweichung in %"));
|
||||
}
|
||||
helfer.linieAusgeben();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue