<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Hilfe bei Hausaufgabe (Näherungsverfahren für Pi)]]></title><description><![CDATA[<p>So hier ist mal die Aufgabenstellung: <a href="http://www.tfh-berlin.de/~radners/WS2007_8/IM/aufgaben/HA2.pdf" rel="nofollow">http://www.tfh-berlin.de/~radners/WS2007_8/IM/aufgaben/HA2.pdf</a></p>
<p>Die Werte für das 6- Eck sind ja Uu6 und Ui6.</p>
<p>Für das 12- Eck müssen die Werte nun in die Formel eingesetzt werden. Für das 24- Eck die Ergebnisse vom 12- Eck usw.</p>
<p>Bisher habe ich das ganze in eine sehr einfache Form gebracht, die mir für das 6- Eck und das 12- Eck die Werte berechnet. Das könnte ich jetzt auch noch ewig weiter führen, bis ich Pi auf 3-4Kommastellen genau raus habe. Jedoch hab ich dann keine if- Anweisung oder for- Schliefe angewandt und wüsste auch nicht, wie er mir nur den Wert für eine Iteration also das 6- Eck anzeigt.</p>
<p>Die Formel beschreibt doch auch schon eine Iteration oder? Die weiteren Werte sollten dann in einer for- Schleife ausgerechnet werden mit den selben Variablen, die nach 4 oder 5 Iterationen abbricht.<br />
Das Problem ist nur, dass ich jetzt 0 Ahnung habe wie ich das realisieren soll. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Wäre für Hilfe sehr dankbar.</p>
<p>Hier ist noch mal der sehr einfache Code, den ich schon geschrieben habe mit den deklarierten Variablen:</p>
<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;cmath&gt;

using namespace std;

int main(int argc, char *argv[])
{

    double Uin;                                                  // Innenkreis
    double Uun;                                                 // Umkreis   
    const long double PiREELL=3.14159265358979323846264338328L;// pi
    const double Uu= 2*sqrt(3);                               // Umfang Umkreis
    const double Ui= 3;                                      // Umfang Innenkreis
    double ite;                                             // Iterationen
    double Pi;                                             // Näherung für Pi
    double Eck = 6;                                       // Eckzahl
    double eck12;                                        // Ecken (nur zum Test)
    double abw;                                         // Abweichung 

    // Pi- Brechnung

    cout &lt;&lt; &quot;PI- Naeherung&quot; &lt;&lt;endl;
    cout &lt;&lt; &quot;                &quot; &lt;&lt; endl;

         eck6:{
         Uun   = Uu;
         Uin   = Ui;      
         Pi    = (Uun+Uin)/2;
         Eck   = Eck;
         abw   = Pi-PiREELL;
         }

                cout &lt;&lt; &quot;Pi ist jetzt:&quot; &lt;&lt; Pi &lt;&lt; endl;
                cout &lt;&lt; &quot;Uu ist jetzt:&quot; &lt;&lt; Uun &lt;&lt; endl;
                cout &lt;&lt; &quot;Ui ist jetzt:&quot; &lt;&lt; Uin &lt;&lt; endl;
                cout &lt;&lt; &quot;Die Abweichung betraegt:&quot; &lt;&lt; abw &lt;&lt; endl;
                cout &lt;&lt; &quot;Die Eckzahl ist jetzt:&quot; &lt;&lt; Eck &lt;&lt; endl;

    cout &lt;&lt; &quot;   &quot; &lt;&lt; endl;

         eck12:{
         Uun    = (2*Ui*Uu)/(Ui+Uu);
         Uin    = sqrt(Ui*Uun);
         Pi     = (Uun+Uin)/2;
         Eck    = 2*Eck;
         abw    = Pi-PiREELL;
         }

                cout &lt;&lt; &quot;Pi ist jetzt:&quot; &lt;&lt; Pi &lt;&lt; endl;
                cout &lt;&lt; &quot;Uu ist jetzt:&quot; &lt;&lt; Uun &lt;&lt; endl;
                cout &lt;&lt; &quot;Ui ist jetzt:&quot; &lt;&lt; Uin &lt;&lt; endl;
                cout &lt;&lt; &quot;Die Abweichung betraegt:&quot; &lt;&lt; abw &lt;&lt; endl;
                cout &lt;&lt; &quot;Die Eckzahl ist jetzt:&quot; &lt;&lt; Eck &lt;&lt; endl;

    cout &lt;&lt; &quot;   &quot; &lt;&lt; endl;

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/198323/hilfe-bei-hausaufgabe-näherungsverfahren-für-pi</link><generator>RSS for Node</generator><lastBuildDate>Fri, 02 Oct 2026 05:57:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/198323.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Nov 2007 17:05:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Hilfe bei Hausaufgabe (Näherungsverfahren für Pi) on Tue, 20 Nov 2007 17:05:43 GMT]]></title><description><![CDATA[<p>So hier ist mal die Aufgabenstellung: <a href="http://www.tfh-berlin.de/~radners/WS2007_8/IM/aufgaben/HA2.pdf" rel="nofollow">http://www.tfh-berlin.de/~radners/WS2007_8/IM/aufgaben/HA2.pdf</a></p>
<p>Die Werte für das 6- Eck sind ja Uu6 und Ui6.</p>
<p>Für das 12- Eck müssen die Werte nun in die Formel eingesetzt werden. Für das 24- Eck die Ergebnisse vom 12- Eck usw.</p>
<p>Bisher habe ich das ganze in eine sehr einfache Form gebracht, die mir für das 6- Eck und das 12- Eck die Werte berechnet. Das könnte ich jetzt auch noch ewig weiter führen, bis ich Pi auf 3-4Kommastellen genau raus habe. Jedoch hab ich dann keine if- Anweisung oder for- Schliefe angewandt und wüsste auch nicht, wie er mir nur den Wert für eine Iteration also das 6- Eck anzeigt.</p>
<p>Die Formel beschreibt doch auch schon eine Iteration oder? Die weiteren Werte sollten dann in einer for- Schleife ausgerechnet werden mit den selben Variablen, die nach 4 oder 5 Iterationen abbricht.<br />
Das Problem ist nur, dass ich jetzt 0 Ahnung habe wie ich das realisieren soll. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Wäre für Hilfe sehr dankbar.</p>
<p>Hier ist noch mal der sehr einfache Code, den ich schon geschrieben habe mit den deklarierten Variablen:</p>
<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;cmath&gt;

using namespace std;

int main(int argc, char *argv[])
{

    double Uin;                                                  // Innenkreis
    double Uun;                                                 // Umkreis   
    const long double PiREELL=3.14159265358979323846264338328L;// pi
    const double Uu= 2*sqrt(3);                               // Umfang Umkreis
    const double Ui= 3;                                      // Umfang Innenkreis
    double ite;                                             // Iterationen
    double Pi;                                             // Näherung für Pi
    double Eck = 6;                                       // Eckzahl
    double eck12;                                        // Ecken (nur zum Test)
    double abw;                                         // Abweichung 

    // Pi- Brechnung

    cout &lt;&lt; &quot;PI- Naeherung&quot; &lt;&lt;endl;
    cout &lt;&lt; &quot;                &quot; &lt;&lt; endl;

         eck6:{
         Uun   = Uu;
         Uin   = Ui;      
         Pi    = (Uun+Uin)/2;
         Eck   = Eck;
         abw   = Pi-PiREELL;
         }

                cout &lt;&lt; &quot;Pi ist jetzt:&quot; &lt;&lt; Pi &lt;&lt; endl;
                cout &lt;&lt; &quot;Uu ist jetzt:&quot; &lt;&lt; Uun &lt;&lt; endl;
                cout &lt;&lt; &quot;Ui ist jetzt:&quot; &lt;&lt; Uin &lt;&lt; endl;
                cout &lt;&lt; &quot;Die Abweichung betraegt:&quot; &lt;&lt; abw &lt;&lt; endl;
                cout &lt;&lt; &quot;Die Eckzahl ist jetzt:&quot; &lt;&lt; Eck &lt;&lt; endl;

    cout &lt;&lt; &quot;   &quot; &lt;&lt; endl;

         eck12:{
         Uun    = (2*Ui*Uu)/(Ui+Uu);
         Uin    = sqrt(Ui*Uun);
         Pi     = (Uun+Uin)/2;
         Eck    = 2*Eck;
         abw    = Pi-PiREELL;
         }

                cout &lt;&lt; &quot;Pi ist jetzt:&quot; &lt;&lt; Pi &lt;&lt; endl;
                cout &lt;&lt; &quot;Uu ist jetzt:&quot; &lt;&lt; Uun &lt;&lt; endl;
                cout &lt;&lt; &quot;Ui ist jetzt:&quot; &lt;&lt; Uin &lt;&lt; endl;
                cout &lt;&lt; &quot;Die Abweichung betraegt:&quot; &lt;&lt; abw &lt;&lt; endl;
                cout &lt;&lt; &quot;Die Eckzahl ist jetzt:&quot; &lt;&lt; Eck &lt;&lt; endl;

    cout &lt;&lt; &quot;   &quot; &lt;&lt; endl;

    system(&quot;PAUSE&quot;);
    return EXIT_SUCCESS;
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1406761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1406761</guid><dc:creator><![CDATA[sonicknight]]></dc:creator><pubDate>Tue, 20 Nov 2007 17:05:43 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei Hausaufgabe (Näherungsverfahren für Pi) on Wed, 21 Nov 2007 21:07:35 GMT]]></title><description><![CDATA[<p>in Deiner Aufgabenstellung steht:<br />
&quot;Lerninhalte: if-Bedingung, for-Schleife, tabellarische cout-Formatierung&quot;</p>
<p>Den Anfang hast Du ja schon gemacht. Statt es für jedes n-Eck hinzuschreiben kannst Du das in einer for-Schleife fassen und auch als Tabelle ausgeben.</p>
<pre><code class="language-cpp">// Startwerte wie gehabt
    double Uu= 2*sqrt(3.0);                               // Umfang Umkreis
    double Ui= 3;                                      // Umfang Innenkreis
    for( ; /*Abbruchkriterium?*/; )
    {
        // -- jetzt eine (!) Zeile der Tabelle ausgeben ...
        // ...

        // anschließend Uu und Ui neu berechnen
        Uu = (2*Ui*Uu)/(Ui+Uu);    // Uu ist jetzt Uun
        Ui = sqrt(Ui*Uu);
    }
</code></pre>
<p>zur formatierten Ausgabe schaue Dir bitte mal setw, setprecision und fixed an.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1407753</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1407753</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Wed, 21 Nov 2007 21:07:35 GMT</pubDate></item></channel></rss>