<?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[Division]]></title><description><![CDATA[<p>Hallo Freunde, Hier seht ihr meinen Quotientenblock.</p>
<pre><code class="language-cpp">int q1 = zaehler / x;							
// Beginn Quotientenblock
					int q2 = x / zaehler;
					int diff = zaehler - x; 
					printf(&quot;DIFF: %d\n&quot;, diff);
					printf(&quot;QW/TW: %d\n&quot;, q1);
					printf(&quot;TW/QW: %d\n&quot;, q2);
</code></pre>
<p>Der Ausdruck dazu ist folgender**<br />
DIFF: 14<br />
QW/TW: 1<br />
TW/QW: 0<br />
TrWurzel= 49 Summe= 1225<br />
QdWurzel= 35 Qudrt= 1225</p>
<p>Zeit: 0</p>
<p>DIFF: 84<br />
QW/TW: 1<br />
TW/QW: 0<br />
TrWurzel= 288 Summe= 41616<br />
QdWurzel= 204 Qudrt= 41616</p>
<p>Zeit: 0</p>
<p>DIFF: 492<br />
QW/TW: 1<br />
TW/QW: 0<br />
TrWurzel= 1681 Summe= 1413721<br />
QdWurzel= 1189 Qudrt= 1413721</p>
<p>**</p>
<p>Irgendwas stimmt nicht, daß er die Division nicht macht. Mit durch Null kann nicht sein, weil laut Ausdruck ja was positives drinn ist in den Zellen. Es kann damit zusammen hängen, daß bei q1 Werte unter Null sind, und die variable die nicht will.</p>
<p>ich weiss nicht weiter,,,,</p>
<pre><code class="language-cpp">#include &lt;Carbon/Carbon.h&gt;
#include &lt;stdio.h&gt;
#include &lt;ctime&gt;
#include &lt;iostream&gt;

using namespace std;
int main (int argc, char * const argv[])
{
	clock_t t1, t2; // Uhranweisung
    long result;
    t1 = clock(); 

	long long Zaehlgrenze = 10000;										// Initialblock	
	long long zaehler = 1;
	long long trigonal = 0;
	printf(&quot;Das Programm sucht innerhalb des Intervalls von 0 bis %d die Zahlen heraus, welche zugleich Quadratzahlen und Trigonalzahlen sind. \n&quot;, Zaehlgrenze);

	while (zaehler &lt; Zaehlgrenze)										// Beginn 1. Schleife
	{
	trigonal = trigonal+zaehler;										// Trigonalzahlerhöhung
		for (long long i=1, x = zaehler/2; x*x &lt;= trigonal; i += ++x)  	// Beginn Schleife 2
				if (trigonal== x*x) 
					{

					int q1 = zaehler / x;								// Beginn Quotientenblock
					int q2 = x / zaehler;
					int diff = zaehler - x; 
					printf(&quot;DIFF: %d\n&quot;, diff);
					printf(&quot;QW/TW: %d\n&quot;, q1);
					printf(&quot;TW/QW: %d\n&quot;, q2);							// Ende Quotientenblock

					cout &lt;&lt; &quot;TrWurzel=\t &quot; &lt;&lt; zaehler  &lt;&lt;&quot;\t&quot; &lt;&lt;&quot; Summe= &quot; &lt;&lt; trigonal  &lt;&lt; &quot;\nQdWurzel= \t &quot; &lt;&lt; x  &lt;&lt; &quot;\t Qudrt= &quot; &lt;&lt; x*x &lt;&lt;  &quot;\n&quot; &lt;&lt;   endl;
					t2 = clock();														// Zeitnahme
					printf(&quot;Zeit: %d\n\n&quot;, (t2-t1));
					zaehler = zaehler*5;
					trigonal = zaehler*(zaehler+1)/2;
					}													// Ende If und Ende Schleife 2 im If-Fall
		//printf(&quot;Zähler %d\n&quot;, zaehler);
		//printf(&quot;trigonal %d\n&quot;, trigonal);
		//printf(&quot;x %d\n&quot;, x);
		//printf(&quot;quadrat %d\n&quot;, x*x);
		zaehler++;														// Zaehlererhöhung
	}																	// Ende Schleife 1
	printf(&quot;Das Programm endet mit Zähler %d\n&quot;, zaehler);				// Abschlussbericht	
	printf(&quot;dessen Trigonalzahl ist %d\n&quot;, trigonal);

    result = static_cast&lt;long&gt;( (t2-t1)/CLOCKS_PER_SEC);
	printf(&quot;Zeit: %d\n&quot;, (t2-t1)); // Zeitdruck
printf(&quot;Resultat: %d\n&quot;, result);
	return 0;	
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/220998/division</link><generator>RSS for Node</generator><lastBuildDate>Tue, 06 Oct 2026 13:07:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/220998.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 24 Aug 2008 12:22:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Division on Sun, 24 Aug 2008 12:22:03 GMT]]></title><description><![CDATA[<p>Hallo Freunde, Hier seht ihr meinen Quotientenblock.</p>
<pre><code class="language-cpp">int q1 = zaehler / x;							
// Beginn Quotientenblock
					int q2 = x / zaehler;
					int diff = zaehler - x; 
					printf(&quot;DIFF: %d\n&quot;, diff);
					printf(&quot;QW/TW: %d\n&quot;, q1);
					printf(&quot;TW/QW: %d\n&quot;, q2);
</code></pre>
<p>Der Ausdruck dazu ist folgender**<br />
DIFF: 14<br />
QW/TW: 1<br />
TW/QW: 0<br />
TrWurzel= 49 Summe= 1225<br />
QdWurzel= 35 Qudrt= 1225</p>
<p>Zeit: 0</p>
<p>DIFF: 84<br />
QW/TW: 1<br />
TW/QW: 0<br />
TrWurzel= 288 Summe= 41616<br />
QdWurzel= 204 Qudrt= 41616</p>
<p>Zeit: 0</p>
<p>DIFF: 492<br />
QW/TW: 1<br />
TW/QW: 0<br />
TrWurzel= 1681 Summe= 1413721<br />
QdWurzel= 1189 Qudrt= 1413721</p>
<p>**</p>
<p>Irgendwas stimmt nicht, daß er die Division nicht macht. Mit durch Null kann nicht sein, weil laut Ausdruck ja was positives drinn ist in den Zellen. Es kann damit zusammen hängen, daß bei q1 Werte unter Null sind, und die variable die nicht will.</p>
<p>ich weiss nicht weiter,,,,</p>
<pre><code class="language-cpp">#include &lt;Carbon/Carbon.h&gt;
#include &lt;stdio.h&gt;
#include &lt;ctime&gt;
#include &lt;iostream&gt;

using namespace std;
int main (int argc, char * const argv[])
{
	clock_t t1, t2; // Uhranweisung
    long result;
    t1 = clock(); 

	long long Zaehlgrenze = 10000;										// Initialblock	
	long long zaehler = 1;
	long long trigonal = 0;
	printf(&quot;Das Programm sucht innerhalb des Intervalls von 0 bis %d die Zahlen heraus, welche zugleich Quadratzahlen und Trigonalzahlen sind. \n&quot;, Zaehlgrenze);

	while (zaehler &lt; Zaehlgrenze)										// Beginn 1. Schleife
	{
	trigonal = trigonal+zaehler;										// Trigonalzahlerhöhung
		for (long long i=1, x = zaehler/2; x*x &lt;= trigonal; i += ++x)  	// Beginn Schleife 2
				if (trigonal== x*x) 
					{

					int q1 = zaehler / x;								// Beginn Quotientenblock
					int q2 = x / zaehler;
					int diff = zaehler - x; 
					printf(&quot;DIFF: %d\n&quot;, diff);
					printf(&quot;QW/TW: %d\n&quot;, q1);
					printf(&quot;TW/QW: %d\n&quot;, q2);							// Ende Quotientenblock

					cout &lt;&lt; &quot;TrWurzel=\t &quot; &lt;&lt; zaehler  &lt;&lt;&quot;\t&quot; &lt;&lt;&quot; Summe= &quot; &lt;&lt; trigonal  &lt;&lt; &quot;\nQdWurzel= \t &quot; &lt;&lt; x  &lt;&lt; &quot;\t Qudrt= &quot; &lt;&lt; x*x &lt;&lt;  &quot;\n&quot; &lt;&lt;   endl;
					t2 = clock();														// Zeitnahme
					printf(&quot;Zeit: %d\n\n&quot;, (t2-t1));
					zaehler = zaehler*5;
					trigonal = zaehler*(zaehler+1)/2;
					}													// Ende If und Ende Schleife 2 im If-Fall
		//printf(&quot;Zähler %d\n&quot;, zaehler);
		//printf(&quot;trigonal %d\n&quot;, trigonal);
		//printf(&quot;x %d\n&quot;, x);
		//printf(&quot;quadrat %d\n&quot;, x*x);
		zaehler++;														// Zaehlererhöhung
	}																	// Ende Schleife 1
	printf(&quot;Das Programm endet mit Zähler %d\n&quot;, zaehler);				// Abschlussbericht	
	printf(&quot;dessen Trigonalzahl ist %d\n&quot;, trigonal);

    result = static_cast&lt;long&gt;( (t2-t1)/CLOCKS_PER_SEC);
	printf(&quot;Zeit: %d\n&quot;, (t2-t1)); // Zeitdruck
printf(&quot;Resultat: %d\n&quot;, result);
	return 0;	
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1570438</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570438</guid><dc:creator><![CDATA[brak]]></dc:creator><pubDate>Sun, 24 Aug 2008 12:22:03 GMT</pubDate></item><item><title><![CDATA[Reply to Division on Sun, 24 Aug 2008 12:33:18 GMT]]></title><description><![CDATA[<p>Was du machst, ist eine Division von Ganzzahlen. Da werden beim Ergebnis immer die Nachkommastellen abgeschnitten. Wenn du Nachkommastellen haben willst, solltest du mit <code>float</code> oder <code>double</code> rechnen. Oder zumindest ein <code>static_cast</code> einbauen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570443</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 24 Aug 2008 12:33:18 GMT</pubDate></item><item><title><![CDATA[Reply to Division on Sun, 24 Aug 2008 12:35:30 GMT]]></title><description><![CDATA[<p>1. Wo deklarierst und definierst du eigentlich deine Variable x?</p>
<p>2. In deiner for-Schleife deklarierst du immer wieder deine Variablen q1, q2, etc. neu. Das ist meiner Meinung nach ein ganz schlechter Stil und erfüllt sicher nicht das, was du dir gedacht hast.</p>
<p>3. Du teilst immer Integerwerte durcheinander. Das führt dazu, dass Nachkommastellen nicht gespeichert werden.</p>
<p>4. Das ist reiner C-Code. Du brauchst also kein &lt;iostream&gt; einbinden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570445</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570445</guid><dc:creator><![CDATA[Berufspenner]]></dc:creator><pubDate>Sun, 24 Aug 2008 12:35:30 GMT</pubDate></item><item><title><![CDATA[Reply to Division on Sun, 24 Aug 2008 12:40:46 GMT]]></title><description><![CDATA[<p>1. wird unter C++ std::cout genutzt und das include sollte so heißen: <code>#include &lt;cstdio&gt;</code></p>
<p>2. musst du für ne &quot;richtige&quot; Division auch float/float bzw double/double rechnen...</p>
<pre><code class="language-cpp">int q2 = x / zaehler;
//bsp.:
int q2 = 100 / 30;
int q2 = 3;
/*alle dezimalstellen werden also einfach abgeschnitten... 99/100 ist also auch 0*/
//--------------------------
float q2 = (float)x / (float)zaehler;
//wieder unser bsp.:
float q2 = 100/30 == 10/3;
float q2 = 3,3333333;
</code></pre>
<ol start="3">
<li></li>
</ol>
<pre><code class="language-cpp">result = static_cast&lt;long&gt;( (t2-t1)/CLOCKS_PER_SEC);
</code></pre>
<p>ist noch immer falsch...</p>
<p>4. ein Thread pro Thema würde auch reichen... (mir kams doch von anfang an bekannt vor - da hätt ichs mir au sparen können : / )<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-220904-and-start-is-10.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-220904-and-start-is-10.html</a></p>
<p>bb</p>
<p>PS: <strong>@all:</strong> ich würds lassen, ihm iwas erklären zu wollen - anscheind is er unfähig zu lesen (wie man am letzten thread merkt)...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570446</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570446</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 24 Aug 2008 12:40:46 GMT</pubDate></item><item><title><![CDATA[Reply to Division on Sun, 24 Aug 2008 12:46:47 GMT]]></title><description><![CDATA[<p>Hallo, also ich hab in Double umgewandelt und die Deklaration in den Dekl. Block an den Anfang verlegt.</p>
<p>Ergebnis:<br />
**<br />
DIFF: 14<br />
QW/TW: 0<br />
TW/QW: 0<br />
TrWurzel= 49 Summe= 1225<br />
QdWurzel= 35 Qudrt= 1225</p>
<p>Zeit: 0</p>
<p>DIFF: 84<br />
QW/TW: 0<br />
TW/QW: 0<br />
TrWurzel= 288 Summe= 41616<br />
QdWurzel= 204 Qudrt= 41616</p>
<p>Zeit: 0</p>
<p>**</p>
<p>Das scheint nicht zu reichen....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570455</guid><dc:creator><![CDATA[brak]]></dc:creator><pubDate>Sun, 24 Aug 2008 12:46:47 GMT</pubDate></item><item><title><![CDATA[Reply to Division on Sun, 24 Aug 2008 12:48:46 GMT]]></title><description><![CDATA[<p>Hallo @all</p>
<p>ER VERSTEHT NICHT ALLES BEIM ERSTEN MAL......</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570459</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570459</guid><dc:creator><![CDATA[brak]]></dc:creator><pubDate>Sun, 24 Aug 2008 12:48:46 GMT</pubDate></item><item><title><![CDATA[Reply to Division on Sun, 24 Aug 2008 12:49:21 GMT]]></title><description><![CDATA[<p>brak schrieb:</p>
<blockquote>
<p>Hallo, also ich hab in Double umgewandelt</p>
</blockquote>
<p>Das glaube ich dir nicht. Bestimmt ist der Resultattyp immer noch <code>int</code> . Aber wenn du nicht bereit bist, den neuen Code zu zeigen, können wir dir auch nicht helfen...</p>
<p>brak schrieb:</p>
<blockquote>
<p>Hallo @all</p>
<p>ER VERSTEHT NICHT ALLES BEIM ERSTEN MAL......</p>
</blockquote>
<p>Kein Grund, für das selbe Problem zwei Threads aufzumachen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570460</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570460</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 24 Aug 2008 12:49:21 GMT</pubDate></item><item><title><![CDATA[Reply to Division on Sun, 24 Aug 2008 12:54:30 GMT]]></title><description><![CDATA[<p>brak schrieb:</p>
<blockquote>
<p>ER VERSTEHT NICHT ALLES BEIM ERSTEN MAL......</p>
</blockquote>
<p>Wie lächerlich... Du kannst ja mal die beiden Threads durchgehen und zählen, wie oft dir jemand erklärt hat, was du falsch gemacht hast...<br />
Ich hab dir dazu auch noch was aus der MSDN kopiert, was du so 1:1 übernehmen konntest - und du hast es einfach ignoriert... Also heul jz mal nich rum und lies noch mal alles in Ruhe durch, probiers noch mal und poste dann noch mal, was du gerade hast oder lass es bleiben, verkauf deinen PC und kauf dir ne Konsole und spiel was ohne Nachdenken...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570464</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570464</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 24 Aug 2008 12:54:30 GMT</pubDate></item><item><title><![CDATA[Reply to Division on Sun, 24 Aug 2008 12:58:56 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">diff = zaehler - x;								// Beginn Quotientenblock
					float q1 = (float)zaehler / (float)x;								
					float q2 = (float)x / (float)zaehler;
</code></pre>
<p><strong>So hab ichs gemacht.</strong><br />
<strong>Das ist das Ergebnis:</strong></p>
<p>DIFF: 84<br />
QW/TW: -1610612736<br />
TW/QW: -1610612736<br />
TWu= 288 Su= 41616<br />
QWu= 204 Qu= 41616</p>
<p>Zeit: 0</p>
<p>DIFF: 492<br />
QW/TW: -2147483648<br />
TW/QW: 1610612736<br />
TWu= 1681 Su= 1413721<br />
QWu= 1189 Qu= 1413721</p>
<p><strong>Das mit dem include # include &lt;sctdio&gt; stimmt auch nicht. Ohne iostream gibts immer ERROR</strong></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570465</guid><dc:creator><![CDATA[brak]]></dc:creator><pubDate>Sun, 24 Aug 2008 12:58:56 GMT</pubDate></item><item><title><![CDATA[Reply to Division on Sun, 24 Aug 2008 13:02:04 GMT]]></title><description><![CDATA[<p>Wir wollen mal nicht ärgerlich werden... Es ist ja alles freiwillig.</p>
<p>Hier den Code zur Controlle.</p>
<pre><code class="language-cpp">#include &lt;Carbon/Carbon.h&gt;
#include &lt;stdio.h&gt;
#include &lt;ctime&gt;
#include &lt;iostream&gt;
//#include &lt;cstdio&gt;
using namespace std;
int main (int argc, char * const argv[])
{
	clock_t t1, t2; // Uhranweisung
    long result;
    t1 = clock(); 

	long long Zaehlgrenze = 10000;										// Initialblock	
	long long zaehler = 1;
	long long trigonal = 0;
	int diff;
	float q1, q2;
	printf(&quot;Das Programm sucht innerhalb des Intervalls von 0 bis %d die Zahlen heraus, welche zugleich Quadratzahlen und Trigonalzahlen sind. \n&quot;, Zaehlgrenze);

	while (zaehler &lt; Zaehlgrenze)										// Beginn 1. Schleife
	{
	trigonal = trigonal+zaehler;										// Trigonalzahlerhöhung
		for (long long i=1, x = zaehler/2; x*x &lt;= trigonal; i += ++x)  	// Beginn Schleife 2
				if (trigonal== x*x) 
					{
					diff = zaehler - x;								// Beginn Quotientenblock
					float q1 = (float)zaehler / (float)x;								
					float q2 = (float)x / (float)zaehler;

					printf(&quot;DIFF: %d\n&quot;, diff);
					printf(&quot;QW/TW: %d\n&quot;, q1);
					printf(&quot;TW/QW: %d\n&quot;, q2);							// Ende Quotientenblock

					cout &lt;&lt; &quot;TWu=\t &quot; &lt;&lt; zaehler  &lt;&lt;&quot;\t&quot; &lt;&lt;&quot; Su= &quot; &lt;&lt; trigonal  &lt;&lt; &quot;\nQWu= \t &quot; &lt;&lt; x  &lt;&lt; &quot;\t Qu= &quot; &lt;&lt; x*x &lt;&lt;  &quot;\n&quot; &lt;&lt;   endl;
					t2 = clock();														// Zeitnahme
					printf(&quot;Zeit: %d\n\n&quot;, (t2-t1));
					zaehler = zaehler*5;
					trigonal = zaehler*(zaehler+1)/2;
					}													// Ende If und Ende Schleife 2 im If-Fall
		//printf(&quot;Zähler %d\n&quot;, zaehler);
		//printf(&quot;trigonal %d\n&quot;, trigonal);
		//printf(&quot;x %d\n&quot;, x);
		//printf(&quot;quadrat %d\n&quot;, x*x);
		zaehler++;														// Zaehlererhöhung
	}																	// Ende Schleife 1
	printf(&quot;Das Programm endet mit Zähler %d\n&quot;, zaehler);				// Abschlussbericht	
	printf(&quot;dessen Trigonalzahl ist %d\n&quot;, trigonal);

    result = static_cast&lt;long&gt;( (t2-t1)/CLOCKS_PER_SEC);
	printf(&quot;Zeit: %d\n&quot;, (t2-t1)); // Zeitdruck
printf(&quot;Resultat: %d\n&quot;, result);
	return 0;	
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1570469</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570469</guid><dc:creator><![CDATA[brak]]></dc:creator><pubDate>Sun, 24 Aug 2008 13:02:04 GMT</pubDate></item><item><title><![CDATA[Reply to Division on Sun, 24 Aug 2008 19:03:02 GMT]]></title><description><![CDATA[<p>auch wenn sich das ganze nicht wirklich bei dir bessert...<br />
Ich hab ma versucht, bissl was lesbares daraus zu machen - hoffe mal, dass das ich damit nichts kaputt gemacht hab ^^ war zu faul zum nachdenken - wieso auch, wenn du das auch nicht machst...</p>
<pre><code class="language-cpp">#include &lt;ctime&gt;
#include &lt;iostream&gt;

int main (int argc, char * const argv[])
  {
    const clock_t t1 (clock ());

    const size_t max (10000);
    size_t trigonal (0);
    std::cout &lt;&lt; &quot;Das Programm sucht innerhalb des Intervalls von 1 bis &quot;
      &lt;&lt; max
      &lt;&lt; &quot; die Zahlen heraus, welche zugleich Quadratzahlen und Trigonalzahlen sind&quot;
      &lt;&lt; std::endl;

    size_t zaehler (0);
    for (; zaehler &lt; max; ++zaehler)
      {
        trigonal += zaehler;
        for (size_t i (1), x = zaehler/2; x*x &lt;= trigonal; i += ++x)
          {
            if (trigonal== x*x) 
              {
                diff = zaehler - x;
                const float q1 = (float)zaehler / (float)x;
                const float q2 = 1 / q1;

                std::cout &lt;&lt; clock () &lt;&lt; std::endl &lt;&lt;
                  &lt;&lt; &quot;\t&quot; &lt;&lt; &quot;DIFF:\t&quot; &lt;&lt; diff &lt;&lt; &quot;\r\n&quot;
                  &lt;&lt; &quot;\t&quot; &lt;&lt; &quot;QW / TW:\t&quot; &lt;&lt; q1 &lt;&lt; &quot;\r\n&quot;
                  &lt;&lt; &quot;\t&quot; &lt;&lt; &quot;TW / QW:\t&quot; &lt;&lt; q2 &lt;&lt; std::endl;

                std::cout &lt;&lt; &quot;\t&quot; &lt;&lt; &quot;TWu=\t&quot; &lt;&lt; zaehler &lt;&lt; &quot;\r\n&quot;
                  &lt;&lt; &quot;\t&quot; &lt;&lt; &quot;Su=\t&quot; &lt;&lt; trigonal &lt;&lt; &quot;\r\n&quot;
                  &lt;&lt; &quot;\t&quot; &lt;&lt; &quot;QWu=\t&quot; &lt;&lt; x &lt;&lt; &quot;\r\n&quot;
                  &lt;&lt; &quot;\t&quot; &lt;&lt; &quot;Qu=\t&quot; &lt;&lt; x*x &lt;&lt; std::endl;

                zaehler *= 5;
                trigonal = zaehler*(zaehler+1) / 2;
              }
          }
      }
    std::cout &lt;&lt; &quot;Das Programm endet mit Zaehler &quot; &lt;&lt; zaehler &lt;&lt; &quot;.\r\n&quot;
      &lt;&lt; &quot;dessen Trigonalzahl ist &quot; &lt;&lt; trigonal;
    const clock_t t2 (clock ());
    const float dt = (double) (t2-t1) / CLOCKS_PER_SEC;
    std::cout &lt;&lt; &quot;Benoetigte Zeit dafuer: &quot; &lt;&lt; dt &lt;&lt; std::endl;
    return 0;	
  }
</code></pre>
<pre><code class="language-cpp">for (size_t i (1), x = zaehler/2; x*x &lt;= trigonal; i += ++x)
  {
    if (trigonal== x*x) {}
  }
</code></pre>
<p>sieht ineffektiv aus, oder? du brauchst davon doch gar nichts - sind alles nur hilfsvariablen, oder?</p>
<p>außerdem ist das alles viel zu lang... versuch doch mal, das ganze mit klassen zu machen...</p>
<pre><code class="language-cpp">/*trigonalzahl.hpp*/
template &lt;class Tnumber, class Tcount = Tnumber&gt;
  class TTrigonalZahl
    {
      private:
        Tcount count;
        Tnumber number;
      public:
        TTrigonalZahl ()    :  count (1), number (1)    {}
        TTrigonalZahl (size_t steps)
          :  count (1), number (1)
          {
            Steps (--steps);
          }
        void Next ()          {number += ++count;}
        void Steps (const size_t count)
          {
            for (size_t i (0); i != count; ++i)
              this-&gt;Next ();
          }
        TTriangonalZahl&amp; operator ++ ()
                              {Next (); return *this;}
        Tnumber Get () const  {return number};
    };
</code></pre>
<p>für das Stoppen würde ich auch ne Klasse bevorzugen...</p>
<pre><code class="language-cpp">/*stopuhr.hpp*/

#include &lt;ctime&gt;

class TTimeDiff
  {
      private:
        const clock_t start;
        float &amp;time;
      public:
        TTimeDiff (float &amp;_time) : start (clock ()), time (_time) {}
        ~TTimeDiff ()             {Now ();}

        void Now ()
          {
            const clock_t end (clock ());
            time = (float) (end-start) / CLOCKS_PER_SEC;
          }
  };
</code></pre>
<p>also haben wir:</p>
<p>(da ich nicht genau verstanden hab, was du nun machen willst und was nicht, hab ichs einfach mal so gemacht)</p>
<pre><code class="language-cpp">#include &quot;trigonalzahl.hpp&quot;
#include &quot;stopuhr.hpp&quot;
#include &lt;iostream&gt;

int main ()
  {
    float time (0);
    TTimeDiff TimeDiff (time);
      {
        size_t max (-1);
        std::cout &lt;&lt; &quot;Geben Sie das Maximum ein&quot;;
        std::cin &gt;&gt; max;
        while (max == -1)
          {
            std::cout &lt;&lt; &quot;Falsche Eingabe - Sie muessen eine ganze Zahl im Bereich von 0...2^31-2 eingeben&quot;;
            std::cin &gt;&gt; max;
          }
        for (TTrigonalZahl &lt;size_t&gt; tzahl; tzahl.Get () &lt; max; ++tzahl)
          {
            TTrigonalZahl &lt;size_t&gt; i (1);
            for (; i.Get () * i.Get () &lt; tzahl.Get (); ++i)
              {}
            if (i.Get () * i.Get () == tzahl.Get ())
              {
                TimeDiff.Now ();
                std::cout &lt;&lt; &quot;[&quot; &lt;&lt; time &lt;&lt; &quot;] Die Trigonalzahl &quot; &lt;&lt; tzahl.Get () &lt;&lt; &quot; ist gleichzeitig das Quadrat einer anderen Trigonalzahl (&quot; &lt;&lt; i &lt;&lt; &quot;)&quot; &lt;&lt; std::endl;
              }
          }
      }
    std::cout &lt;&lt; &quot;Benoetigte Zeit:&quot; &lt;&lt; time &lt;&lt; std::endl;
  }
</code></pre>
<p>hatte gerade lange weile - kannst mich ja ma davon überzeugen, dass die Zeit ne ganz verschwendet war...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1570647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1570647</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sun, 24 Aug 2008 19:03:02 GMT</pubDate></item></channel></rss>