<?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[Größter gemeinsamer Teiler]]></title><description><![CDATA[<p>Hallo, im C++ Primer gibt es folgenden Code für den &quot;greatest common divisor&quot;:</p>
<pre><code class="language-cpp">int gcd(int v1, int v2)
{
    while(v2){
        int temp = v2;
        v2 = v1 % v2;
        v1 = temp;
    }
    return v1;
}
</code></pre>
<p>So, was genau passiert mit dieser while-Schleife?Als was bedeutet</p>
<pre><code class="language-cpp">while(v2)
</code></pre>
<p>und was genau läuft in dieser Schleife eigentlicha b? Ich kapier das nicht so ganz.<br />
Danke für jede Antwort <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title="=)"
      alt="🙂"
    /></p>
<p>-GhostfaceChilla-</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/296467/größter-gemeinsamer-teiler</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 22:39:13 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/296467.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Dec 2011 12:49:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Größter gemeinsamer Teiler on Mon, 05 Dec 2011 12:49:00 GMT]]></title><description><![CDATA[<p>Hallo, im C++ Primer gibt es folgenden Code für den &quot;greatest common divisor&quot;:</p>
<pre><code class="language-cpp">int gcd(int v1, int v2)
{
    while(v2){
        int temp = v2;
        v2 = v1 % v2;
        v1 = temp;
    }
    return v1;
}
</code></pre>
<p>So, was genau passiert mit dieser while-Schleife?Als was bedeutet</p>
<pre><code class="language-cpp">while(v2)
</code></pre>
<p>und was genau läuft in dieser Schleife eigentlicha b? Ich kapier das nicht so ganz.<br />
Danke für jede Antwort <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title="=)"
      alt="🙂"
    /></p>
<p>-GhostfaceChilla-</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2153271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2153271</guid><dc:creator><![CDATA[GhostfaceChilla]]></dc:creator><pubDate>Mon, 05 Dec 2011 12:49:00 GMT</pubDate></item><item><title><![CDATA[Reply to Größter gemeinsamer Teiler on Mon, 05 Dec 2011 12:52:56 GMT]]></title><description><![CDATA[<p><code>while(v2)</code> ist gleichbedeutend mit <code>while(v2 != 0)</code> und % ist der Modulo operator. Damit solltest du dir das eigentlich selbst erkären können.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2153276</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2153276</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Mon, 05 Dec 2011 12:52:56 GMT</pubDate></item><item><title><![CDATA[Reply to Größter gemeinsamer Teiler on Mon, 05 Dec 2011 13:11:49 GMT]]></title><description><![CDATA[<p>Ok, aber tut mir leid ich kapiers nicht. Sagen wir ich habe die Zahlen 15 un 123, d.h 3 ist der größe gemeinsame Teiler.<br />
Somit würde ja in der Schleife tmp zu 15 werden und v2 wäre ja noch 123.<br />
Danach soll ja v2 nen neuen wert bekommen, also wird 15/123 geteilt und v2 ist dann der rest oder?<br />
Aber ich weis nicht, wie man hier auf 3 kommt durch dieses Schema.</p>
<p>-GhostfaceChilla-</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2153288</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2153288</guid><dc:creator><![CDATA[GhostfaceChilla]]></dc:creator><pubDate>Mon, 05 Dec 2011 13:11:49 GMT</pubDate></item><item><title><![CDATA[Reply to Größter gemeinsamer Teiler on Mon, 05 Dec 2011 13:18:58 GMT]]></title><description><![CDATA[<p>Dann geh doch die Schleife mal auf Papier Schritt für Schritt durch...</p>
<p>v1 = 15, v2 = 123</p>
<p>1. Durchlauf<br />
temp = v2 (123)<br />
v2 = v1 % v2 (15 % 123) = ?<br />
v1 = temp (123)</p>
<p>2. Durchlauf<br />
...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2153292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2153292</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 05 Dec 2011 13:18:58 GMT</pubDate></item><item><title><![CDATA[Reply to Größter gemeinsamer Teiler on Mon, 05 Dec 2011 13:20:17 GMT]]></title><description><![CDATA[<p>GhostfaceChilla schrieb:</p>
<blockquote>
<p>Ok, aber tut mir leid ich kapiers nicht. Sagen wir ich habe die Zahlen 15 un 123, d.h 3 ist der größe gemeinsame Teiler.</p>
</blockquote>
<p>Genauer gesagt: v1 = 15, v2 = 123.</p>
<blockquote>
<p>Somit würde ja in der Schleife tmp zu 15 werden und v2 wäre ja noch 123.</p>
</blockquote>
<p>Da wird's schon falsch. Im ersten Schleifendurchlauf wird temp=123, dann v1=15 (Rest von 15/123), dann v2=123. Im ersten Durchlauf werden also nur die Werte getauscht.</p>
<p>Den zweiten Durchlauf machst Du jetzt mal selber. Und dann immer mechanisch weiter, bis v2=0.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2153295</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2153295</guid><dc:creator><![CDATA[SG1]]></dc:creator><pubDate>Mon, 05 Dec 2011 13:20:17 GMT</pubDate></item><item><title><![CDATA[Reply to Größter gemeinsamer Teiler on Mon, 05 Dec 2011 13:41:36 GMT]]></title><description><![CDATA[<p>Also habs ma durchgerechnet:</p>
<pre><code class="language-cpp">1. temp = 123
   v2 = 15
   v1 = 123

2. temp = 15
   v2 = 5
   v1 = 15

3. temp = 5   
   v2 = 3
   v1 = 5

4. temp = 3 
   v2 = 2
   v1 = 3     // hier wäre v1 = 3, aber v2 != 0 ??

5. temp = 2
   v2 = 1
   v1 = 2

6. temp = 1  
   v2 = 0     // hier wäre v2 = 0, aber v1 wäre 1??
   v1 = 1
</code></pre>
<p>Wo liegt mein Denkfehler??</p>
<p>-GhostfaceChilla-</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2153305</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2153305</guid><dc:creator><![CDATA[GhostfaceChilla]]></dc:creator><pubDate>Mon, 05 Dec 2011 13:41:36 GMT</pubDate></item><item><title><![CDATA[Reply to Größter gemeinsamer Teiler on Mon, 05 Dec 2011 13:50:59 GMT]]></title><description><![CDATA[<p>Du hast dich in Schritt 2 vertan.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2153314</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2153314</guid><dc:creator><![CDATA[Caligulaminus]]></dc:creator><pubDate>Mon, 05 Dec 2011 13:50:59 GMT</pubDate></item><item><title><![CDATA[Reply to Größter gemeinsamer Teiler on Mon, 05 Dec 2011 13:57:03 GMT]]></title><description><![CDATA[<p>Ah ok, dann kommt bei Schritt 3 schon die Lösung <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
Da v2 = 15 % 3 ist ja v2 = 0 ok.<br />
Danke.</p>
<p>-GhostfaceChilla-</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2153319</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2153319</guid><dc:creator><![CDATA[GhostfaceChilla]]></dc:creator><pubDate>Mon, 05 Dec 2011 13:57:03 GMT</pubDate></item></channel></rss>