<?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[Sieb des Eratosthenes ... schwachsinnige Ausgabe]]></title><description><![CDATA[<p>hi,</p>
<p>ich habe dieses kleine Programm zum finden von Primzahlen nach dem Algorithmus vom Sieb des Eratosthenes <a href="http://de.wikipedia.org/wiki/Sieb_des_Eratosthenes" rel="nofollow">http://de.wikipedia.org/wiki/Sieb_des_Eratosthenes</a> geschrieben:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;

using namespace std;

class Zahl
{
	public:
		int wert;
		bool prim;
};

int main ()
{
	const int LIMIT = 100;

	Zahl Zahlen[LIMIT];

	/* ------------------- Initialisieren--------------------------- */
	for (int i = 0; i &lt;= LIMIT; i++)
	{
		Zahlen[LIMIT].wert = i;		// Durchzählen ...
		Zahlen[LIMIT].prim = true;	// Alle Zahlen als Primzahlen ansehen
	}

	/* ---------------------Durchsieben---------------------------- */
	int Sieb = 2;

	while (Sieb &lt;= sqrt(LIMIT))
	{
		for (int j = 0; j &lt;= LIMIT; j++)
		{
			if (Zahlen[j].prim == true)
				if ((Zahlen[j].prim % Sieb) == 0)
					Zahlen[j].prim = false;
		}

		Sieb++;
	}

	// Test

	cout &lt;&lt; Zahlen[77].wert &lt;&lt; &quot;: &quot; &lt;&lt; Zahlen[77].prim;

	return 0;
}
</code></pre>
<p>Leider bekomme ich als Ausgabe:</p>
<pre><code>4007032: 104
</code></pre>
<p>Vielen Dank!</p>
<p>mfg</p>
<p>Joachim</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/120226/sieb-des-eratosthenes-schwachsinnige-ausgabe</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 05:39:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/120226.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 10 Sep 2005 15:46:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Sieb des Eratosthenes ... schwachsinnige Ausgabe on Sat, 10 Sep 2005 15:46:56 GMT]]></title><description><![CDATA[<p>hi,</p>
<p>ich habe dieses kleine Programm zum finden von Primzahlen nach dem Algorithmus vom Sieb des Eratosthenes <a href="http://de.wikipedia.org/wiki/Sieb_des_Eratosthenes" rel="nofollow">http://de.wikipedia.org/wiki/Sieb_des_Eratosthenes</a> geschrieben:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;math.h&gt;

using namespace std;

class Zahl
{
	public:
		int wert;
		bool prim;
};

int main ()
{
	const int LIMIT = 100;

	Zahl Zahlen[LIMIT];

	/* ------------------- Initialisieren--------------------------- */
	for (int i = 0; i &lt;= LIMIT; i++)
	{
		Zahlen[LIMIT].wert = i;		// Durchzählen ...
		Zahlen[LIMIT].prim = true;	// Alle Zahlen als Primzahlen ansehen
	}

	/* ---------------------Durchsieben---------------------------- */
	int Sieb = 2;

	while (Sieb &lt;= sqrt(LIMIT))
	{
		for (int j = 0; j &lt;= LIMIT; j++)
		{
			if (Zahlen[j].prim == true)
				if ((Zahlen[j].prim % Sieb) == 0)
					Zahlen[j].prim = false;
		}

		Sieb++;
	}

	// Test

	cout &lt;&lt; Zahlen[77].wert &lt;&lt; &quot;: &quot; &lt;&lt; Zahlen[77].prim;

	return 0;
}
</code></pre>
<p>Leider bekomme ich als Ausgabe:</p>
<pre><code>4007032: 104
</code></pre>
<p>Vielen Dank!</p>
<p>mfg</p>
<p>Joachim</p>
]]></description><link>https://www.c-plusplus.net/forum/post/869248</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/869248</guid><dc:creator><![CDATA[zahlenrausch]]></dc:creator><pubDate>Sat, 10 Sep 2005 15:46:56 GMT</pubDate></item><item><title><![CDATA[Reply to Sieb des Eratosthenes ... schwachsinnige Ausgabe on Sat, 10 Sep 2005 16:04:18 GMT]]></title><description><![CDATA[<p>Deine beiden for Schleifen gehen 1 zu weit (101 Durchläufe). Statt &lt;= nur &lt; nehmen. Damit ist zumindest vor Beginn des Algorithmus bereits der Speicher verhunzt.<br />
Des weiteren solltest Du in Deiner ersten Schleife als Array Index i benutzen und nicht immer ausserhalb des Arrays schreiben.<br />
Damit erklärt sich dann auch die Ausgabe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/869258</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/869258</guid><dc:creator><![CDATA[niemand]]></dc:creator><pubDate>Sat, 10 Sep 2005 16:04:18 GMT</pubDate></item><item><title><![CDATA[Reply to Sieb des Eratosthenes ... schwachsinnige Ausgabe on Sat, 10 Sep 2005 23:41:41 GMT]]></title><description><![CDATA[<p>Vielen Dank. Hab ich nich gesehn.</p>
<p>Joachim</p>
]]></description><link>https://www.c-plusplus.net/forum/post/869456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/869456</guid><dc:creator><![CDATA[zahlenrausch]]></dc:creator><pubDate>Sat, 10 Sep 2005 23:41:41 GMT</pubDate></item></channel></rss>