<?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[Ausgabe von Collatz Folge zählen]]></title><description><![CDATA[<p>Hallo zusammen,<br />
ich bin Neuling und hoffe mein Post ist hier richtig.</p>
<p>In Informatik haben wir die Aufgabe einen Code (C++) zu schreiben der die Collatz Folge beinhaltet.</p>
<p>n/2<br />
3n+1</p>
<p>Die Collatzfolge soll innerhalb von einer Million sein und man soll die längste Zahlenfolge für n herausfinden.</p>
<p>Meine Frage:<br />
Wie zähle ich bei n=21</p>
<p>64, 32, 16, 8, 4, 2, 1</p>
<p>dass es sich bei der Zahl 21 um insgesamt 7 Zahlen handelt?</p>
<p>Ich hoffe, dass ich mich nicht allzu kompliziert ausgedrückt habe.</p>
<p>Danke im Voraus.</p>
<p>MfG<br />
dfs</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/325426/ausgabe-von-collatz-folge-zählen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 11:47:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/325426.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 01 May 2014 14:32:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ausgabe von Collatz Folge zählen on Thu, 01 May 2014 14:33:53 GMT]]></title><description><![CDATA[<p>Hallo zusammen,<br />
ich bin Neuling und hoffe mein Post ist hier richtig.</p>
<p>In Informatik haben wir die Aufgabe einen Code (C++) zu schreiben der die Collatz Folge beinhaltet.</p>
<p>n/2<br />
3n+1</p>
<p>Die Collatzfolge soll innerhalb von einer Million sein und man soll die längste Zahlenfolge für n herausfinden.</p>
<p>Meine Frage:<br />
Wie zähle ich bei n=21</p>
<p>64, 32, 16, 8, 4, 2, 1</p>
<p>dass es sich bei der Zahl 21 um insgesamt 7 Zahlen handelt?</p>
<p>Ich hoffe, dass ich mich nicht allzu kompliziert ausgedrückt habe.</p>
<p>Danke im Voraus.</p>
<p>MfG<br />
dfs</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396988</guid><dc:creator><![CDATA[derfragensteller]]></dc:creator><pubDate>Thu, 01 May 2014 14:33:53 GMT</pubDate></item><item><title><![CDATA[Reply to Ausgabe von Collatz Folge zählen on Thu, 01 May 2014 14:48:43 GMT]]></title><description><![CDATA[<p>Was hast du denn schon? Weißt du grundsätzlich, wie man irgendwas zählt? Kannst du die Collatzfolge zu einer Startzahl (ohne Zählung) ausgeben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396989</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396989</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 01 May 2014 14:48:43 GMT</pubDate></item><item><title><![CDATA[Reply to Ausgabe von Collatz Folge zählen on Thu, 01 May 2014 14:48:56 GMT]]></title><description><![CDATA[<p>1+1+1+...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396990</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396990</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Thu, 01 May 2014 14:48:56 GMT</pubDate></item><item><title><![CDATA[Reply to Ausgabe von Collatz Folge zählen on Thu, 01 May 2014 14:59:57 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>Was hast du denn schon? Weißt du grundsätzlich, wie man irgendwas zählt? Kannst du die Collatzfolge zu einer Startzahl (ohne Zählung) ausgeben?</p>
</blockquote>
<p>Hallo,<br />
ja die Ausgabe meiner Collatzfolge funktioniert.</p>
<p>Aber wie die Zählung meiner Ausgabe erfolgen soll, verstehe ich leider nicht so.</p>
<p>Hier die Ausgabe zur Zahl 995173:<br />
Wie zähle ich nun die Anzahl der folgenden Zahlen? Es sind insgesamt 46 Zahlen.</p>
<p>---Count starts at 995173---<br />
2985520, 1492760, 746380, 373190, 186595, 559786, 279893, 839680, 419840, 209920, 104960, 52480, 26240, 13120, 6560, 3280, 1640, 820, 410, 205, 616, 308, 154, 77, 232, 116, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1,</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396991</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396991</guid><dc:creator><![CDATA[derfragensteller]]></dc:creator><pubDate>Thu, 01 May 2014 14:59:57 GMT</pubDate></item><item><title><![CDATA[Reply to Ausgabe von Collatz Folge zählen on Thu, 01 May 2014 15:32:37 GMT]]></title><description><![CDATA[<p>Zeig mal Deinen Code.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396993</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396993</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Thu, 01 May 2014 15:32:37 GMT</pubDate></item><item><title><![CDATA[Reply to Ausgabe von Collatz Folge zählen on Thu, 01 May 2014 15:42:52 GMT]]></title><description><![CDATA[<p>Ganz grob: Du definierst eine <code>int</code> -Variable und inkrementierst (addierst 1) diese in jedem Schleifendurchlauf. Du wirst eine Schleife haben, anders ist das kaum möglich (außer durch Rekursion, aber das kann man direkt umschreiben, und selbst da ist es in abgewandelter Form (mit Funktionsparameter) möglich).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2396995</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2396995</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Thu, 01 May 2014 15:42:52 GMT</pubDate></item><item><title><![CDATA[Reply to Ausgabe von Collatz Folge zählen on Thu, 01 May 2014 17:44:22 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Zeig mal Deinen Code.</p>
</blockquote>
<pre><code>#include &lt;iostream&gt;
using namespace std;

int main () {

    long int n;

    for(int i=14; i&lt;1000000;) {

        if(i%2==0) {
            n=i/2;
            cout &lt;&lt; n &lt;&lt; &quot;, &quot;;
        }
        else; {
            n=3*i+1;
            cout &lt;&lt; n &lt;&lt; &quot;, &quot;;
        }
        while(n!=1){

            if (n%2==0){
                n=n/2;
                cout &lt;&lt; n &lt;&lt; &quot;, &quot;;
            } else {
                n=3*n+1;
                cout &lt;&lt; n &lt;&lt; &quot;, &quot;;
            }

        }
        i++;
        cout &lt;&lt; &quot; \n&quot;;
        cout &lt;&lt; &quot; \n&quot;;
        cout &lt;&lt; &quot;---&quot;;
        cout &lt;&lt; &quot;Count starts at &quot; &lt;&lt; i &lt;&lt; &quot;---&quot; &quot;\n&quot;;
    }

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2397010</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2397010</guid><dc:creator><![CDATA[derfragensteller]]></dc:creator><pubDate>Thu, 01 May 2014 17:44:22 GMT</pubDate></item><item><title><![CDATA[Reply to Ausgabe von Collatz Folge zählen on Thu, 01 May 2014 17:57:50 GMT]]></title><description><![CDATA[<p>Die Zeilen 10 bis 17 sind irgendwie unnötig, oder? Setz doch einfach n = i (und zieh das n in die Schleife).</p>
<p>Zum Thema: Jetzt fügst du eine Variable hinzu, die du vor jedem Durchlauf deiner Folge (also vor Zeile 18) auf 0 setzt und dann im jedem Durchlauf der Schleife um 1 erhöhst. Wenn die Schleife fertig ist, kannst du am Zähler ablesen, wie oft sie durchlaufen wurde.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2397015</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2397015</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 01 May 2014 17:57:50 GMT</pubDate></item><item><title><![CDATA[Reply to Ausgabe von Collatz Folge zählen on Thu, 01 May 2014 18:45:31 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Die Zeilen 10 bis 17 sind irgendwie unnötig, oder? Setz doch einfach n = i (und zieh das n in die Schleife).</p>
<p>Zum Thema: Jetzt fügst du eine Variable hinzu, die du vor jedem Durchlauf deiner Folge (also vor Zeile 18) auf 0 setzt und dann im jedem Durchlauf der Schleife um 1 erhöhst. Wenn die Schleife fertig ist, kannst du am Zähler ablesen, wie oft sie durchlaufen wurde.</p>
</blockquote>
<p>Vielen Dank für den Tipp, aber irgendwie zählt der nicht richtig. Hab den Code etwas geändert.</p>
<pre><code>#include &lt;iostream&gt;
using namespace std;

int main () {

    long int n;
    int m=0;

    for(int i=7; i&lt;9;) {

        if(i%2==0) {
            n=i/2;
            cout &lt;&lt; n &lt;&lt; &quot;, &quot;;
        }
        else; {
            n=3*i+1;
            cout &lt;&lt; n &lt;&lt; &quot;, &quot;;
        }
        while(n!=1){
            m++;
            if (n%2==0){
                n=n/2;
                cout &lt;&lt; n &lt;&lt; &quot;, &quot;;
            } else {
                n=3*n+1;
                cout &lt;&lt; n &lt;&lt; &quot;, &quot;;
            }
        }
        cout &lt;&lt; &quot;\n&quot;;
        cout &lt;&lt; m &lt;&lt;&quot; Zahlen. &quot; &quot;\n&quot;;
        i++;
        cout &lt;&lt; &quot; \n&quot;;
        cout &lt;&lt; &quot; \n&quot;;
        cout &lt;&lt; &quot;---&quot;;
        cout &lt;&lt; &quot;Count starts at &quot; &lt;&lt; i &lt;&lt; &quot;---&quot; &quot;\n&quot;;
    }
return 0;
}
</code></pre>
<p>Ausgabe bei Collatzfolge für 7:<br />
22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1,<br />
15 Zahlen.</p>
<p>Ausgabe bei Collatzfolge für 8:<br />
---Count starts at 8---<br />
4, 25, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1,<br />
38 Zahlen.</p>
<p>Bei der 1. Zahl zählt er um -1 und in der folgenden Collatzfolge zählt er zuviel ???</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2397017</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2397017</guid><dc:creator><![CDATA[derfragensteller]]></dc:creator><pubDate>Thu, 01 May 2014 18:45:31 GMT</pubDate></item><item><title><![CDATA[Reply to Ausgabe von Collatz Folge zählen on Thu, 01 May 2014 19:10:31 GMT]]></title><description><![CDATA[<p>Lies meinen Beitrag noch einmal genau. Wenn das nicht reicht, benutz einen Debugger.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2397019</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2397019</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 01 May 2014 19:10:31 GMT</pubDate></item></channel></rss>