<?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[int::max will nicht]]></title><description><![CDATA[<p>Hier der Code und die Frage.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;limits&gt;

using namespace std;

int main(int argc, char* argv[]) {

int maxint = numeric_limits&lt;int&gt;::max(); // Integer max in Int-Typ

// Folgende Rechnung zeigt nur Nullen in einer Endlosschleife
// Setze ich eine Zahl ein, zb. 2000000000 (Zwei Milliarden) kommen die
// richtigen Ergebnisse und die Schleife terminiert
/* --&gt; Warum nicht mit maxint? &lt;-- */

for (int rechnung = 1, mp = 1; rechnung &lt; maxint; ++mp) {
    rechnung *= mp;
    cout &lt;&lt; rechnung &lt;&lt; endl;
}

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/257064/int-max-will-nicht</link><generator>RSS for Node</generator><lastBuildDate>Thu, 10 Sep 2026 18:12:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/257064.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 22 Dec 2009 08:58:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to int::max will nicht on Tue, 22 Dec 2009 08:58:42 GMT]]></title><description><![CDATA[<p>Hier der Code und die Frage.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;limits&gt;

using namespace std;

int main(int argc, char* argv[]) {

int maxint = numeric_limits&lt;int&gt;::max(); // Integer max in Int-Typ

// Folgende Rechnung zeigt nur Nullen in einer Endlosschleife
// Setze ich eine Zahl ein, zb. 2000000000 (Zwei Milliarden) kommen die
// richtigen Ergebnisse und die Schleife terminiert
/* --&gt; Warum nicht mit maxint? &lt;-- */

for (int rechnung = 1, mp = 1; rechnung &lt; maxint; ++mp) {
    rechnung *= mp;
    cout &lt;&lt; rechnung &lt;&lt; endl;
}

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1826242</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826242</guid><dc:creator><![CDATA[mussgehen]]></dc:creator><pubDate>Tue, 22 Dec 2009 08:58:42 GMT</pubDate></item><item><title><![CDATA[Reply to int::max will nicht on Tue, 22 Dec 2009 09:02:25 GMT]]></title><description><![CDATA[<p>Bei Zahl einsetzen meine ich natürlich die Bedingung in der Schleife. 2 Milliarden anstatt maxint, die ja mit Integer-Maximum initialisiert ist.<br />
long Typ bringt selben Effekt.</p>
<blockquote>
<p>rechnung &lt; maxint;</p>
</blockquote>
<p>GCC + Code Blocks Stable (8.02)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1826245</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826245</guid><dc:creator><![CDATA[mussgehen]]></dc:creator><pubDate>Tue, 22 Dec 2009 09:02:25 GMT</pubDate></item><item><title><![CDATA[Reply to int::max will nicht on Tue, 22 Dec 2009 09:07:07 GMT]]></title><description><![CDATA[<p>Was meinst Du denn, was die <strong>größte darstellbare</strong> Integerzahl <strong>+1</strong> liefert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1826246</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826246</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Tue, 22 Dec 2009 09:07:07 GMT</pubDate></item><item><title><![CDATA[Reply to int::max will nicht on Tue, 22 Dec 2009 09:08:32 GMT]]></title><description><![CDATA[<p>Dann setz mal was primzahliges ein <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 />
Dein Problem ist ein klassischer Overflow. Du wirst es nie erreichen, dass das Ergebnis deiner Rechnung exakt maxint wird, das ist die einzige Möglichkeit dass die Schleife abbricht.<br />
Ich erhalte im übrigen nicht lauter 0-en:</p>
<pre><code>./main
1                       
2                       
6                       
24                      
120                     
720                     
5040                    
40320                   
362880                  
3628800                 
39916800                
479001600               
1932053504              
1278945280              
2004310016              
2004189184              
-288522240              
-898433024              
109641728               
-2102132736             
-1195114496             
-522715136              
862453760               
-775946240              
2076180480              
-1853882368             
1484783616              
-1375731712             
-1241513984             
1409286144              
738197504               
-2147483648             
-2147483648             
0                       
0                       
0                       
0                       
0                       
0                       
0                       
0                       
0                       
0                       
0                       
0                       
0
</code></pre>
<p>Am Anfang gibt es also schon noch Ergebnisse.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1826248</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826248</guid><dc:creator><![CDATA[Gurgler]]></dc:creator><pubDate>Tue, 22 Dec 2009 09:08:32 GMT</pubDate></item><item><title><![CDATA[Reply to int::max will nicht on Tue, 22 Dec 2009 09:16:13 GMT]]></title><description><![CDATA[<p>Das war ein krasser Denkfehler von mir, ich wusste das es einen Overflow gibt aber ich habe falsch gedacht.<br />
Ich prüfe nun auf &gt; 0 und die Schleife terminiert.</p>
<p>Danke an alle.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1826252</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1826252</guid><dc:creator><![CDATA[mussgehen]]></dc:creator><pubDate>Tue, 22 Dec 2009 09:16:13 GMT</pubDate></item></channel></rss>