<?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[Überprüfen auf Primzahlen]]></title><description><![CDATA[<p>#include &lt;iostream&gt;<br />
#include &lt;iomanip&gt;<br />
using namespace std;</p>
<p>int main()<br />
{<br />
int zahl;<br />
cout &lt;&lt; &quot;Geben Sie eine Zahl ein: &quot; ;<br />
cin &gt;&gt; zahl;</p>
<p>for (int teiler=2; teiler &lt; zahl; teiler++)<br />
{<br />
if (zahl % teiler ==0)<br />
{<br />
cout &lt;&lt; &quot;Die Zahl lässt sich durch &quot; &lt;&lt; teiler &lt;&lt; &quot; teilen und ist deshalb keine Primzahl&quot; &lt;&lt; endl;<br />
break;<br />
}</p>
<p>if(teiler ==zahl-1)<br />
cout &lt;&lt; &quot;Die Zahl ist eine Primzahl= &quot; &lt;&lt; zahl;<br />
}<br />
}</p>
<p>ich würde gerne noch das er mir alle teiler ausgibt wenn es keine Primzahl ist und nicht nur einen!!</p>
<p>kann mir einer helfen?!<br />
danke im vor-raus</p>
<p>grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/321959/überprüfen-auf-primzahlen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 16:58:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/321959.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 30 Nov 2013 16:09:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sat, 30 Nov 2013 16:09:12 GMT]]></title><description><![CDATA[<p>#include &lt;iostream&gt;<br />
#include &lt;iomanip&gt;<br />
using namespace std;</p>
<p>int main()<br />
{<br />
int zahl;<br />
cout &lt;&lt; &quot;Geben Sie eine Zahl ein: &quot; ;<br />
cin &gt;&gt; zahl;</p>
<p>for (int teiler=2; teiler &lt; zahl; teiler++)<br />
{<br />
if (zahl % teiler ==0)<br />
{<br />
cout &lt;&lt; &quot;Die Zahl lässt sich durch &quot; &lt;&lt; teiler &lt;&lt; &quot; teilen und ist deshalb keine Primzahl&quot; &lt;&lt; endl;<br />
break;<br />
}</p>
<p>if(teiler ==zahl-1)<br />
cout &lt;&lt; &quot;Die Zahl ist eine Primzahl= &quot; &lt;&lt; zahl;<br />
}<br />
}</p>
<p>ich würde gerne noch das er mir alle teiler ausgibt wenn es keine Primzahl ist und nicht nur einen!!</p>
<p>kann mir einer helfen?!<br />
danke im vor-raus</p>
<p>grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369097</guid><dc:creator><![CDATA[DerAnfängerc++]]></dc:creator><pubDate>Sat, 30 Nov 2013 16:09:12 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sat, 30 Nov 2013 16:10:11 GMT]]></title><description><![CDATA[<p>Schau dir an, was break macht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369098</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369098</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sat, 30 Nov 2013 16:10:11 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sat, 30 Nov 2013 16:12:10 GMT]]></title><description><![CDATA[<p>ja weiß ich schon, wie schreib ich das um das er mir das break erst macht wenn er alle teiler mir ausgegeben hat. ich komm da nicht weiter</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369101</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369101</guid><dc:creator><![CDATA[DerAnfängerc++]]></dc:creator><pubDate>Sat, 30 Nov 2013 16:12:10 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sat, 30 Nov 2013 16:20:42 GMT]]></title><description><![CDATA[<p>DerAnfängerc++ schrieb:</p>
<blockquote>
<p>ja weiß ich schon, wie schreib ich das um das er mir das break erst macht wenn er alle teiler mir ausgegeben hat. ich komm da nicht weiter</p>
</blockquote>
<p>Lösche die Zeile mit dem ' <code>break</code> ' doch einfach und schaue, was dann passiert ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369105</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369105</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Sat, 30 Nov 2013 16:20:42 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sat, 30 Nov 2013 16:24:33 GMT]]></title><description><![CDATA[<p>dann gibt er mir zwar alle teiler aus aber auch die letzte if abfrage....<br />
hab schon versucht mit einer zweiten schleife aber klappt irgendwie nicht</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369106</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369106</guid><dc:creator><![CDATA[DerAnfängerc++]]></dc:creator><pubDate>Sat, 30 Nov 2013 16:24:33 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sat, 30 Nov 2013 16:29:50 GMT]]></title><description><![CDATA[<p>Du musst dir halt merken, ob es einen Teiler gab. Mit einem <a href="http://de.wikipedia.org/wiki/Flag_%28Informatik%29" rel="nofollow">Flag</a>.</p>
<pre><code>int flag = 0;
...

  if (zahl % teiler ==0)
  { flag = 1;
  } 
...

if (flag == 1) 
{
  &quot;Die Zahl ist (k)eine Primzahl!&quot;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2369111</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369111</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Sat, 30 Nov 2013 16:29:50 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sat, 30 Nov 2013 16:33:28 GMT]]></title><description><![CDATA[<p>DerAnfängerc++ schrieb:</p>
<blockquote>
<p>dann gibt er mir zwar alle teiler aus aber auch die letzte if abfrage....<br />
hab schon versucht mit einer zweiten schleife aber klappt irgendwie nicht</p>
</blockquote>
<p>gut erkannt, jetzt bist Du schon einen Schritt weiter.</p>
<p>DirkB schrieb:</p>
<blockquote>
<p>Du musst dir halt merken, ob es einen Teiler gab. Mit einem <a href="http://de.wikipedia.org/wiki/Flag_%28Informatik%29" rel="nofollow">Flag</a>.</p>
</blockquote>
<p>Das wäre die Lösung, und dafür gibt es in C++ den Datentyp <code>bool</code> .</p>
<pre><code>#include &lt;iostream&gt;
// #include &lt;iomanip&gt; // ist hier nicht notwendig
using namespace std;

int main()
{
    int zahl;
    cout &lt;&lt; &quot;Geben Sie eine Zahl ein: &quot; ;
    cin &gt;&gt; zahl;

    bool zahl_ist_prim = true; // wir nehmen an, dass die Zahl eine Primzahl ist, bis jetzt wurde ja noch kein Teiler gefunden
    for (int teiler=2; teiler &lt; zahl; teiler++)
    {
        if (zahl % teiler ==0)
        {
            cout &lt;&lt; &quot;Die Zahl lässt sich durch &quot; &lt;&lt; teiler &lt;&lt; &quot; teilen und ist deshalb keine Primzahl&quot; &lt;&lt; endl;
            zahl_ist_prim = false; // es existier ein Teiler, also keine Primzahl
        }
    }
    if(zahl_ist_prim)
        cout &lt;&lt; &quot;Die Zahl ist eine Primzahl= &quot; &lt;&lt; zahl;
}
</code></pre>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369112</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369112</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Sat, 30 Nov 2013 16:33:28 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sat, 30 Nov 2013 19:11:53 GMT]]></title><description><![CDATA[<p>Super Danke an alle!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369139</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369139</guid><dc:creator><![CDATA[DerAnfängerc++]]></dc:creator><pubDate>Sat, 30 Nov 2013 19:11:53 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sun, 01 Dec 2013 00:41:24 GMT]]></title><description><![CDATA[<p>gabs da nicht sowas, das man den teiler nicht bis zur zahl laufen lassen muss, sondern das auch die wurzel der zahl ausreicht?</p>
<p>also for(teiler=2;teiler&lt;sqrt(zahl);zahl++)?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369170</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369170</guid><dc:creator><![CDATA[ACnut]]></dc:creator><pubDate>Sun, 01 Dec 2013 00:41:24 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sun, 01 Dec 2013 09:40:35 GMT]]></title><description><![CDATA[<p>ACnut schrieb:</p>
<blockquote>
<p>gabs da nicht sowas, das man den teiler nicht bis zur zahl laufen lassen muss, sondern das auch die wurzel der zahl ausreicht?</p>
<p>also for(teiler=2;teiler&lt;sqrt(zahl);zahl++)?</p>
</blockquote>
<p>Ja, man braucht auch nur alle ungerade Zahlen zu checken, nachdem man den Check durch 2 gemacht hat.<br />
Der TE will aber alle Teiler einer Zahl finden (Gut, da braucht man auch nur bis zur Wurzel* zu gehen und das Gegenstück zu berechnen).</p>
<p><em>: Wobei man sqrt noch nicht einmal braucht. Die Bedingung teiler</em>teiler &lt;= zahl ist wesentlich effizienter.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369185</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369185</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 01 Dec 2013 09:40:35 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sun, 01 Dec 2013 11:10:54 GMT]]></title><description><![CDATA[<blockquote>
<p>Die Bedingung teiler*teiler &lt;= zahl ist wesentlich effizienter.</p>
</blockquote>
<p>Das stimmt für große Zahlen doch nicht. Eine Million Multiplikationen? (Bzw. Eine Million Shifts mit Inkrement, nach +2n+1)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369198</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 01 Dec 2013 11:10:54 GMT</pubDate></item><item><title><![CDATA[Reply to Überprüfen auf Primzahlen on Sun, 01 Dec 2013 14:39:32 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p><em>: Wobei man sqrt noch nicht einmal braucht. Die Bedingung teiler</em>teiler &lt;= zahl ist wesentlich effizienter.</p>
</blockquote>
<p>Wenn man bis N=100 geht vielleicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369213</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369213</guid><dc:creator><![CDATA[otze]]></dc:creator><pubDate>Sun, 01 Dec 2013 14:39:32 GMT</pubDate></item></channel></rss>