<?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[Berechnung des ggT zweier natuerlicher Zahlen a und b nach Euklid -&amp;gt; Problem]]></title><description><![CDATA[<p>Hallo, die Aufgabe sollte mit der Topic geklärt sein hoffe ich!<br />
Habe hier nun ein Programm, welches bei einigen Zahlenpaaren auch richtige Werte gibt, bei dem Beispiel (der Aufgabe wo a=25 und b=15 (ggT(25,15)=10)) jedoch nicht! Und auch bei einigen anderen Beispielen kommen falsche Ergebnisse raus, kann mir jemand sagen woran das liegt?</p>
<p>Thx im Voraus<br />
Schnittenhainy</p>
<p>Hier der Code</p>
<pre><code class="language-cpp">#include &lt;iostream.h&gt;

int main()
{
	int a,b,x;
	int r = 0;
	cout &lt;&lt; &quot; *** Berechnung des ggT zweier natuerlicher Zahlen a und b nach Euklid *** &quot; &lt;&lt; endl &lt;&lt; endl;
	cout &lt;&lt; &quot; Geben Sie einen ganzzahligen Wert fuer a ein! &quot;;
	cin &gt;&gt; a;
	cout &lt;&lt; &quot; Geben Sie einen ganzzahligen Wert fuer b ein! &quot;;
	cin &gt;&gt; b;
// (1) - Setze m=a , n=b	
	int m = a;
	int n = b;

	while (r &lt; 0 || r &gt; 0);
	{

	// (2) - Ist m&lt;n, so vertausche m und n	
	if (m&lt;n)
		{
			cout &lt;&lt; &quot; Vertausche a und b, da a &lt; b &quot; &lt;&lt; endl;
			x = m;
			m = n;
			n = x;
		}
	// (3) - Berechne r = m%n
	r = m%n;
	m = n;
	n = r;

	}
cout &lt;&lt; &quot; &quot; &lt;&lt; m &lt;&lt; endl;

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/128742/berechnung-des-ggt-zweier-natuerlicher-zahlen-a-und-b-nach-euklid-gt-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 25 Aug 2026 21:00:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/128742.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 06 Dec 2005 18:33:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Berechnung des ggT zweier natuerlicher Zahlen a und b nach Euklid -&amp;gt; Problem on Tue, 06 Dec 2005 18:33:36 GMT]]></title><description><![CDATA[<p>Hallo, die Aufgabe sollte mit der Topic geklärt sein hoffe ich!<br />
Habe hier nun ein Programm, welches bei einigen Zahlenpaaren auch richtige Werte gibt, bei dem Beispiel (der Aufgabe wo a=25 und b=15 (ggT(25,15)=10)) jedoch nicht! Und auch bei einigen anderen Beispielen kommen falsche Ergebnisse raus, kann mir jemand sagen woran das liegt?</p>
<p>Thx im Voraus<br />
Schnittenhainy</p>
<p>Hier der Code</p>
<pre><code class="language-cpp">#include &lt;iostream.h&gt;

int main()
{
	int a,b,x;
	int r = 0;
	cout &lt;&lt; &quot; *** Berechnung des ggT zweier natuerlicher Zahlen a und b nach Euklid *** &quot; &lt;&lt; endl &lt;&lt; endl;
	cout &lt;&lt; &quot; Geben Sie einen ganzzahligen Wert fuer a ein! &quot;;
	cin &gt;&gt; a;
	cout &lt;&lt; &quot; Geben Sie einen ganzzahligen Wert fuer b ein! &quot;;
	cin &gt;&gt; b;
// (1) - Setze m=a , n=b	
	int m = a;
	int n = b;

	while (r &lt; 0 || r &gt; 0);
	{

	// (2) - Ist m&lt;n, so vertausche m und n	
	if (m&lt;n)
		{
			cout &lt;&lt; &quot; Vertausche a und b, da a &lt; b &quot; &lt;&lt; endl;
			x = m;
			m = n;
			n = x;
		}
	// (3) - Berechne r = m%n
	r = m%n;
	m = n;
	n = r;

	}
cout &lt;&lt; &quot; &quot; &lt;&lt; m &lt;&lt; endl;

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/936069</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/936069</guid><dc:creator><![CDATA[Schnittenhainy]]></dc:creator><pubDate>Tue, 06 Dec 2005 18:33:36 GMT</pubDate></item><item><title><![CDATA[Reply to Berechnung des ggT zweier natuerlicher Zahlen a und b nach Euklid -&amp;gt; Problem on Tue, 06 Dec 2005 20:10:23 GMT]]></title><description><![CDATA[<p>Schnittenhainy schrieb:</p>
<blockquote>
<p>while (r &lt; 0 || r &gt; 0);</p>
</blockquote>
<p>da ist doch ein &quot;;&quot; zuviel</p>
]]></description><link>https://www.c-plusplus.net/forum/post/936174</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/936174</guid><dc:creator><![CDATA[b7f7]]></dc:creator><pubDate>Tue, 06 Dec 2005 20:10:23 GMT</pubDate></item><item><title><![CDATA[Reply to Berechnung des ggT zweier natuerlicher Zahlen a und b nach Euklid -&amp;gt; Problem on Tue, 06 Dec 2005 20:12:26 GMT]]></title><description><![CDATA[<p>und du solltest dann auf n!=0 testen den r ist am begin 0</p>
]]></description><link>https://www.c-plusplus.net/forum/post/936177</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/936177</guid><dc:creator><![CDATA[b7f7]]></dc:creator><pubDate>Tue, 06 Dec 2005 20:12:26 GMT</pubDate></item><item><title><![CDATA[Reply to Berechnung des ggT zweier natuerlicher Zahlen a und b nach Euklid -&amp;gt; Problem on Tue, 06 Dec 2005 20:48:23 GMT]]></title><description><![CDATA[<p>Wie wärs wenn du davon einfach eine Rekursion machst? <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>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;
int eZ,zZ;
int ggT(int a,int b)
{
	if(b==0)
	return a;
	else
	return ggT(b,a%b);
}
void main()
{
	cout&lt;&lt;&quot;Gib die erste Zahl ein: &quot;;
	cin&gt;&gt;eZ;
	cout&lt;&lt;&quot;\nNun bitte die zweite Zahl: &quot;;
	cin&gt;&gt;zZ;
	cout&lt;&lt;&quot;\n&quot;&lt;&lt;ggT(eZ,zZ)&lt;&lt;&quot; ist der ggT!&quot;;
}
</code></pre>
<p>Ich finde, mit einer Rekursion ists wesentlich einfacher!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/936200</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/936200</guid><dc:creator><![CDATA[AltesTestament]]></dc:creator><pubDate>Tue, 06 Dec 2005 20:48:23 GMT</pubDate></item><item><title><![CDATA[Reply to Berechnung des ggT zweier natuerlicher Zahlen a und b nach Euklid -&amp;gt; Problem on Tue, 06 Dec 2005 21:27:27 GMT]]></title><description><![CDATA[<p>thx @ b7f7 für die Hinweise, habe das Programm jetzt soweit verbessert und verändert, so dass es auch funktioniert <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>
<pre><code class="language-cpp">#include &lt;iostream.h&gt;

int main()
{
marke:
	int a,b,x;
	int r = 5;
	cout &lt;&lt; &quot; ************************************************************************* &quot; &lt;&lt; endl;
	cout &lt;&lt; &quot; *** Berechnung des ggT zweier natuerlicher Zahlen a und b nach Euklid *** &quot; &lt;&lt; endl;
	cout &lt;&lt; &quot; ************************************************************************* &quot; &lt;&lt; endl &lt;&lt; endl;
	cout &lt;&lt; &quot; \tGeben Sie einen ganzzahligen Wert fuer a ein! &quot;;
	cin &gt;&gt; a;
	cout &lt;&lt; endl;
	cout &lt;&lt; &quot; \tGeben Sie einen ganzzahligen Wert fuer b ein! &quot;;
	cin &gt;&gt; b;
	cout &lt;&lt; endl;
	if (a == 0 || b == 0)
	{
		cout &lt;&lt; &quot; \tEine Ihrer Eingaben ist = 0 und somit ungueltig!&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot; \tZurueck zur Eingabe...&quot; &lt;&lt; endl &lt;&lt; endl;
		goto marke;
	}
// (1) - Setze m=a , n=b	
	int m = a;
	int n = b;

	while (r != 0)
	{

	// (2) - Ist m&lt;n, so vertausche m und n	
	if (m&lt;n)
		{
			cout &lt;&lt; &quot; \tVertausche a und b, da a &lt; b... &quot; &lt;&lt; endl;
			x = m;
			m = n;
			n = x;
		}
	// (3) - Berechne r = m%n
	r = m%n;
	m = n;
	n = r;

	}
cout &lt;&lt; &quot; \tggT(a,b) = &quot; &lt;&lt; m &lt;&lt; endl &lt;&lt; endl;

	return 0;
}
</code></pre>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/11883">@AltesTestament</a>: Bin leider noch ziemlich unerfahren und neu in Sachen C++ und Rekursion sagt mir noch nicht wirklich was, habe das Programm allerdings ausprobiert und es ist wirklich einfacher allerdings für mich noch nicht ganz verständlich. Ich müsste mir erst &quot;Rekursion&quot; erklären / erklären lassen <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 />
Trotzdem thx für den Tipp / deine Mühen</p>
<p>cYa Schnittenhainy</p>
]]></description><link>https://www.c-plusplus.net/forum/post/936227</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/936227</guid><dc:creator><![CDATA[Schnittenhainy]]></dc:creator><pubDate>Tue, 06 Dec 2005 21:27:27 GMT</pubDate></item></channel></rss>