<?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[Zufallszahl nach Größe ordnen ?]]></title><description><![CDATA[<p>Hallo ,<br />
ich habe gerade ein Programm geschrieben ,welches eine Reihe von 6 Zufallstzahl zwichen 0 bis 49 ausgeben kann .</p>
<p>[i] = Anzahl der Zufallszahlen<br />
[j] = Anzahl der Reihen</p>
<pre><code>#include &lt;iostream.h&gt;
int main()
{
int i,j,anz,k;
int tipp[6][100];
/*-----------------------------------------------*/
do{
   cout&lt;&lt;&quot;Geben Sie die Anzahl der Tipps ein:&quot;;
   cin&gt;&gt;anz;
   }
   while(anz&lt;1||anz&gt;100);
/*----------------------------------------------*/

for ( j=0;j&lt;anz;j++)
  { for (i=0;i&lt;6; i++)
     { tipp[i][j]=random(49)+1;
       cout&lt;&lt;tipp[i][j]&lt;&lt;&quot;\t&quot;;
     }
    cout&lt;&lt;&quot;\n&quot;; 
  } 
  getchar();
  return 0;
}
</code></pre>
<p>so weit so gut, jetzt möchte ich diese 6 Zufallszahl nur noch nach Größe ordnen , hab aber keinen Plan ,wie ich das realiseiren kann <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /><br />
kann jemand mir weiter helfen :p<br />
mfG.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/261698/zufallszahl-nach-größe-ordnen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 03:41:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/261698.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 22 Feb 2010 15:46:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zufallszahl nach Größe ordnen ? on Mon, 22 Feb 2010 15:46:52 GMT]]></title><description><![CDATA[<p>Hallo ,<br />
ich habe gerade ein Programm geschrieben ,welches eine Reihe von 6 Zufallstzahl zwichen 0 bis 49 ausgeben kann .</p>
<p>[i] = Anzahl der Zufallszahlen<br />
[j] = Anzahl der Reihen</p>
<pre><code>#include &lt;iostream.h&gt;
int main()
{
int i,j,anz,k;
int tipp[6][100];
/*-----------------------------------------------*/
do{
   cout&lt;&lt;&quot;Geben Sie die Anzahl der Tipps ein:&quot;;
   cin&gt;&gt;anz;
   }
   while(anz&lt;1||anz&gt;100);
/*----------------------------------------------*/

for ( j=0;j&lt;anz;j++)
  { for (i=0;i&lt;6; i++)
     { tipp[i][j]=random(49)+1;
       cout&lt;&lt;tipp[i][j]&lt;&lt;&quot;\t&quot;;
     }
    cout&lt;&lt;&quot;\n&quot;; 
  } 
  getchar();
  return 0;
}
</code></pre>
<p>so weit so gut, jetzt möchte ich diese 6 Zufallszahl nur noch nach Größe ordnen , hab aber keinen Plan ,wie ich das realiseiren kann <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /><br />
kann jemand mir weiter helfen :p<br />
mfG.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859614</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859614</guid><dc:creator><![CDATA[kaizuki]]></dc:creator><pubDate>Mon, 22 Feb 2010 15:46:52 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl nach Größe ordnen ? on Mon, 22 Feb 2010 15:57:04 GMT]]></title><description><![CDATA[<p><a href="http://www.cplusplus.com/reference/algorithm/sort/" rel="nofollow">http://www.cplusplus.com/reference/algorithm/sort/</a><br />
<a href="http://ittk.falb.at/pt/unterlagen/vcppk/bubble_sort.html" rel="nofollow">http://ittk.falb.at/pt/unterlagen/vcppk/bubble_sort.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859619</guid><dc:creator><![CDATA[freaky]]></dc:creator><pubDate>Mon, 22 Feb 2010 15:57:04 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl nach Größe ordnen ? on Mon, 22 Feb 2010 16:23:12 GMT]]></title><description><![CDATA[<p>Sieht so aus, wie Lottozahlen - aber ich sehe nicht, dass du irgendwo prüfst, ob die Zahl schon mal vor kam...<br />
Deshalb wird bei Lotto-Zahlen auch immer ein random_shuffle empfohlen:</p>
<pre><code class="language-cpp">#include &lt;algorithm&gt;
#include &lt;cstdlib&gt;
#include &lt;time&gt;
#include &lt;vector&gt;

int main()
{
	std::vector&lt;int&gt; zahlen;
	zahlen.reserve(49);
	for(int i(1); i != 49; ++i)
		zahlen.push_back(i);

	std::srand(unsigned(std::time()));
	std::random_shuffle(zahlen.begin(), zahlen.end());

	std::sort(zahlen.begin(), zahlen.begin()+6);

	for(int i(0); i != 7; ++i)
		std::cout &lt;&lt; zahlen[i] &lt;&lt; &quot;, &quot;;
}
</code></pre>
<p>hier mal eine anfängerfreundliche Version</p>
<p>ich hoffe, es hilft dir weiter...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859642</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859642</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 22 Feb 2010 16:23:12 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl nach Größe ordnen ? on Mon, 22 Feb 2010 16:36:17 GMT]]></title><description><![CDATA[<p>Oder mit Kanonen auf Spatzen schießen ^^</p>
<p>Man könnte ja auch die Zufallswerte solange in ein std:set schieben bis 6 Elemente vorhanden sind ^^. Sortieren geht dann auch über STL</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859651</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859651</guid><dc:creator><![CDATA[sirchillalot]]></dc:creator><pubDate>Mon, 22 Feb 2010 16:36:17 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl nach Größe ordnen ? on Mon, 22 Feb 2010 16:47:22 GMT]]></title><description><![CDATA[<p>An dieser Stelle natürlich obligatorisch ein Programm, dass tatsächlich nur 6 Zufallszahlen zieht. Nicht 49(?) wie std::random_shuffle und auch nicht potentiell unendlich viele wie die Methode mit dem std::set.</p>
<pre><code class="language-cpp">#include&lt;vector&gt;
#include&lt;iostream&gt;
#include&lt;cstdlib&gt;
#include&lt;cstddef&gt;
#include&lt;ctime&gt;

using namespace std;

const int minimum = 1;
const int maximum = 49;
const size_t anzahl = 6;

int main()
{
  // Abbildung zwischen Zufallswerten und gezogenen Zahlen
  vector&lt;int&gt; zahlen;

  // Füllen:
  for (int i=minimum; i&lt;=maximum; ++i) zahlen.push_back(i);

  // Zufallszahlen ziehen:
  srand ( time(0) );
  for (size_t i=0; i&lt;anzahl; ++i)
    {
      // Zufallszahl im Intervall [0, zahlen.size()]
      int random = rand() % (zahlen.size());
      cout &lt;&lt; i+1 &lt;&lt; &quot;. Zahl: &quot; &lt;&lt; zahlen[random] &lt;&lt;endl;
      // Gezogenes Element aus der Liste löschen:
      zahlen[random] = zahlen.back();
      zahlen.pop_back();
    }
}
</code></pre>
<p>Sortieren geht dann mit einem beliebigen Sortieralgorithmus, beispielsweise std::sort.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859663</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 22 Feb 2010 16:47:22 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl nach Größe ordnen ? on Mon, 22 Feb 2010 18:38:35 GMT]]></title><description><![CDATA[<p>hi, erstmal danke für eure Hilfbereitschaft <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="😃"
    /> .<br />
ich hätte nicht gedacht,dass ich so schnell und vor allem so viele Hilfe bekommt <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="🙂"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /> ,<br />
eure Lösungsvorschläge sind sehr ausführlich erklärt ,sie enthalten jedoch zu viele Befehle,die ich noch nicht kannte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /><br />
kann ich nur mit Schleife die Zufallszahlen sortieren ? <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=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859711</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859711</guid><dc:creator><![CDATA[kaizuki]]></dc:creator><pubDate>Mon, 22 Feb 2010 18:38:35 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl nach Größe ordnen ? on Mon, 22 Feb 2010 18:52:55 GMT]]></title><description><![CDATA[<p>kaizuki schrieb:</p>
<blockquote>
<p>kann ich nur mit Schleife die Zufallszahlen sortieren ? <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=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>Dazu guck dir mal das verlinkte BubbleSort an. Was die Effizienz angeht, ist Bubblesort zwar extrem schlecht, dafür ist es recht leicht verständlich. Was ich sogar noch etwas leicher verständlich finde, ist Selection Sort:<br />
<a href="http://en.wikipedia.org/wiki/Selection_sort" rel="nofollow">http://en.wikipedia.org/wiki/Selection_sort</a><br />
Das ist schon effizienter und entspricht ungefähr dem, wie ein normaler Mensch (kein <em>Informatiker</em>) sortiert. Bei Bubblesort habe ich immer das Gefühl, dass man sich mit Absicht einen schlechten Algorithmus ausgedacht hat.</p>
<p>Beide sind sehr einfach nur mit Schleifen umsetzbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859718</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859718</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 22 Feb 2010 18:52:55 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl nach Größe ordnen ? on Mon, 22 Feb 2010 19:24:24 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Bei Bubblesort habe ich immer das Gefühl, dass man sich mit Absicht einen schlechten Algorithmus ausgedacht hat.</p>
</blockquote>
<p>Das hat definitiv was. Kein normaler Mensch sortiert seine Dinge, in dem sie jeweils mit dem Nachbarding austauscht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1859739</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1859739</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 22 Feb 2010 19:24:24 GMT</pubDate></item></channel></rss>