<?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[Primzahlenberechnung?]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe einen Codeschnipsel, der die Primzahlen berechnet (es geht um Operationsüberladung glaub ich)</p>
<pre><code class="language-cpp">void Natural::printPrimes() const
{
	Natural counter = 2;
	Natural tmpValue = value;
	while (tmpValue.getValue() &gt; counter.getValue())
	{
		if(0 == (tmpValue % counter))
		{
			cout &lt;&lt; counter.getValue() &lt;&lt; &quot; &quot;;
			tmpValue = tmpValue / counter;
			continue;
		}
		counter = counter + 1;
	}
	cout &lt;&lt; tmpValue.getValue();
}
</code></pre>
<p>Kann mir jemand erklären, was genau da passiert?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/149787/primzahlenberechnung</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 08:33:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/149787.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 09 Jun 2006 11:21:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Primzahlenberechnung? on Fri, 09 Jun 2006 11:21:52 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe einen Codeschnipsel, der die Primzahlen berechnet (es geht um Operationsüberladung glaub ich)</p>
<pre><code class="language-cpp">void Natural::printPrimes() const
{
	Natural counter = 2;
	Natural tmpValue = value;
	while (tmpValue.getValue() &gt; counter.getValue())
	{
		if(0 == (tmpValue % counter))
		{
			cout &lt;&lt; counter.getValue() &lt;&lt; &quot; &quot;;
			tmpValue = tmpValue / counter;
			continue;
		}
		counter = counter + 1;
	}
	cout &lt;&lt; tmpValue.getValue();
}
</code></pre>
<p>Kann mir jemand erklären, was genau da passiert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074522</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074522</guid><dc:creator><![CDATA[Gunnar_FH]]></dc:creator><pubDate>Fri, 09 Jun 2006 11:21:52 GMT</pubDate></item><item><title><![CDATA[Reply to Primzahlenberechnung? on Fri, 09 Jun 2006 11:22:57 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">Natural Natural::crossSum(const Natural&amp; number) const
{
	if (number.getValue() &lt; 10)
		return number;
	return crossSum(crossSum(number/10)+(number%10));
}
</code></pre>
<p>Versteh ich auch net <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":-/"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074525</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074525</guid><dc:creator><![CDATA[Gunnar_FH]]></dc:creator><pubDate>Fri, 09 Jun 2006 11:22:57 GMT</pubDate></item><item><title><![CDATA[Reply to Primzahlenberechnung? on Fri, 09 Jun 2006 11:33:26 GMT]]></title><description><![CDATA[<p>So wie ich das verstehe, gibt dir die erste Methode aus, durch welche Zahlen tmpValue teilbar ist. Die Suche beginnt für count = 2 als möglichen Teiler. Sobald tmpValue durch count teilbar ist, wird sie auch dadurch geteilt, um weniger Rechenoperationen zu benötigen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074535</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074535</guid><dc:creator><![CDATA[Flotti]]></dc:creator><pubDate>Fri, 09 Jun 2006 11:33:26 GMT</pubDate></item><item><title><![CDATA[Reply to Primzahlenberechnung? on Fri, 09 Jun 2006 11:53:31 GMT]]></title><description><![CDATA[<p>mir ist vor allem dieser Teil nicht ganz klar:</p>
<pre><code class="language-cpp">if(0 == (tmpValue % counter))
        {
            cout &lt;&lt; counter.getValue() &lt;&lt; &quot; &quot;;
            tmpValue = tmpValue / counter;
            continue;
        }
        counter = counter + 1;
    }
    cout &lt;&lt; tmpValue.getValue();
</code></pre>
<p>es wird geprüft ob tmpvalue % counter gleich null ist und dann tmpvalue durch counter geteilt und das ganze dann sofort von vorne ohne das der rest der schleife durchlaufen wird ? wozu?</p>
<p>und was ist mit der anderen Funktion?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074545</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074545</guid><dc:creator><![CDATA[Gunnar_FH]]></dc:creator><pubDate>Fri, 09 Jun 2006 11:53:31 GMT</pubDate></item><item><title><![CDATA[Reply to Primzahlenberechnung? on Fri, 09 Jun 2006 11:57:20 GMT]]></title><description><![CDATA[<p>Gunnar_FH schrieb:</p>
<blockquote>
<p>es wird geprüft ob tmpvalue % counter gleich null ist und dann tmpvalue durch counter geteilt und das ganze dann sofort von vorne ohne das der rest der schleife durchlaufen wird ? wozu?</p>
</blockquote>
<p>Weil es sein kann, dass der Wert mehrmals durch denselben Primfaktor teilbar ist.</p>
<blockquote>
<p>und was ist mit der anderen Funktion?</p>
</blockquote>
<p>Die bildet die Quersumme, indem sie die Zahl zerlegt. Die letzte Stelle (number % 10) wird zur Quersumme der übrigen Stellen (rekursiver Aufruf mit number / 10) addiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074547</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074547</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Fri, 09 Jun 2006 11:57:20 GMT</pubDate></item><item><title><![CDATA[Reply to Primzahlenberechnung? on Fri, 09 Jun 2006 12:19:03 GMT]]></title><description><![CDATA[<p>könntest Du mir das eventuell an der Zahl 9992 erläutern? Also die einzelnen Schritte bei beiden funktionen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074571</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074571</guid><dc:creator><![CDATA[Gunnar_FH]]></dc:creator><pubDate>Fri, 09 Jun 2006 12:19:03 GMT</pubDate></item><item><title><![CDATA[Reply to Primzahlenberechnung? on Fri, 09 Jun 2006 12:20:55 GMT]]></title><description><![CDATA[<p>Lass dir doch die einzelnen Schritte in der Schleife ausgeben, dann kannst du es selbst nachvollziehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074575</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074575</guid><dc:creator><![CDATA[DarthZiu]]></dc:creator><pubDate>Fri, 09 Jun 2006 12:20:55 GMT</pubDate></item><item><title><![CDATA[Reply to Primzahlenberechnung? on Fri, 09 Jun 2006 12:25:15 GMT]]></title><description><![CDATA[<p>Hm..? ich kriegs net mal im debuger hin *total überfordert* <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f622.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--crying_face"
      title=";("
      alt="😢"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074581</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074581</guid><dc:creator><![CDATA[Gunnar_FH]]></dc:creator><pubDate>Fri, 09 Jun 2006 12:25:15 GMT</pubDate></item><item><title><![CDATA[Reply to Primzahlenberechnung? on Fri, 09 Jun 2006 12:38:00 GMT]]></title><description><![CDATA[<p>Sollst ja auch nicht den Debugger nehmen. Lauf die Schleife durch und lass dir mittels cout die Variablen an den geeigneten Stellen auf der Konsole ausgeben. Dann siehst du was dort passiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074598</guid><dc:creator><![CDATA[DarthZiu]]></dc:creator><pubDate>Fri, 09 Jun 2006 12:38:00 GMT</pubDate></item></channel></rss>