You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Plaintext
		
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Plaintext
		
	
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();
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |