Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo,

folgender Code soll die Zahl Pi nach dem Archimedes Verfahren annähern. Das Näherwungsverfahren arbeitet mit 2 n-ecken, eines einem Kreis einbeschrieben, eines fasst den Kreis ein. Das Verhältnis der Flächen der n-Ecke entspricht pi.

mein Problem ist, dass mein Programm nur einmal durhc die Schleife läuft, in der pi angenähert wird. Allerdings sollte dies öfter erfolgen, um genauere Werte zu liefen.

Mein Code:


 public static void main(String[] args) {

        double a, b, i;

        double pi, fehler;

        int zaehler;

        zaehler = 0;

        a = (2*Math.sqrt(3));

        b = 3;

        i = 0;

        if (a!={

            a = (double)(2*a*b)/(a+;

            b = (double)(Math.sqrt(a*);

            zaehler = zaehler + 1;

        }

        pi = a;

        fehler = 100 - (pi*100/Math.PI);

        System.out.printf("Die Archimedische Näherung von pi beträgt: %g\n"

                + " Zur Berechnung wurden %d Schritte benötigt.\n"

                + "Der Fehler beträgt %g Prozent", pi, zaehler, fehler);

    }

[/code]

Ich Hoffe die Problembeschreibung war hinreichend genau. Danke schonmal für eure Hilfe :)

Bearbeitet von flashpixx
Code-Tags eingefügt

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.