<?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[Frage zur Optimierung von Programm]]></title><description><![CDATA[<p>Ich sollte ein Programm schreiben das die ASCII-Tabelle mit den Werten von 30 bis 129 ausgibt und bei denen die Zeichen 30-32 und 127-129 als Leerzeichen dargestellt werden. Außerdem sollte ein Rahmen mit den Zahlen und dieser gestrichelten Linie drumherum.<br />
Hat zwar ein wenig gedauert aber hier ist es:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main() {
	char zeichen;
	int zeichenwert1, zeichenwert2, zeichenwert3;
	cout &lt;&lt; &quot;    0 1 2 3 4 5 6 7 8 9&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;  +--------------------&quot; &lt;&lt; endl;
	for (zeichenwert1 = 3; zeichenwert1 &lt;= 12; zeichenwert1++) {
		if (zeichenwert1 &lt;= 9) {
			cout &lt;&lt; &quot; &quot; &lt;&lt; zeichenwert1 &lt;&lt; &quot;| &quot;;
		}
		else {
			cout &lt;&lt; zeichenwert1 &lt;&lt; &quot;| &quot;;
		}
		for (zeichenwert2 = 0 ; zeichenwert2 &lt;=9 ; zeichenwert2++) {
			zeichenwert3 = zeichenwert2 + zeichenwert1 * 10;
			if (zeichenwert3 &lt; 33 || zeichenwert3 &gt;= 127) {
				cout &lt;&lt; &quot;  &quot;;
			}
			else {
				zeichen = zeichenwert3;
				cout &lt;&lt; zeichen &lt;&lt; &quot; &quot;;
			}
		}
		cout &lt;&lt; endl;
	}

	system(&quot;pause&quot;);
	return 0;
}
</code></pre>
<p>Da ich noch ziemlich am Anfang bin, was programmieren angeht, wollte ich mal fragen ob es vielleicht kürzere/einfachere Wege gibt als meinen. Vielleicht wo man Dinge einsparen könnte usw... zu Lernzwecken halt. <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="🙂"
    /></p>
<p>Herzlichen Dank für ihre Aufmerksamkeit ... <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/topic/287728/frage-zur-optimierung-von-programm</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 09:26:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/287728.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Jun 2011 22:48:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zur Optimierung von Programm on Thu, 02 Jun 2011 22:48:31 GMT]]></title><description><![CDATA[<p>Ich sollte ein Programm schreiben das die ASCII-Tabelle mit den Werten von 30 bis 129 ausgibt und bei denen die Zeichen 30-32 und 127-129 als Leerzeichen dargestellt werden. Außerdem sollte ein Rahmen mit den Zahlen und dieser gestrichelten Linie drumherum.<br />
Hat zwar ein wenig gedauert aber hier ist es:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main() {
	char zeichen;
	int zeichenwert1, zeichenwert2, zeichenwert3;
	cout &lt;&lt; &quot;    0 1 2 3 4 5 6 7 8 9&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;  +--------------------&quot; &lt;&lt; endl;
	for (zeichenwert1 = 3; zeichenwert1 &lt;= 12; zeichenwert1++) {
		if (zeichenwert1 &lt;= 9) {
			cout &lt;&lt; &quot; &quot; &lt;&lt; zeichenwert1 &lt;&lt; &quot;| &quot;;
		}
		else {
			cout &lt;&lt; zeichenwert1 &lt;&lt; &quot;| &quot;;
		}
		for (zeichenwert2 = 0 ; zeichenwert2 &lt;=9 ; zeichenwert2++) {
			zeichenwert3 = zeichenwert2 + zeichenwert1 * 10;
			if (zeichenwert3 &lt; 33 || zeichenwert3 &gt;= 127) {
				cout &lt;&lt; &quot;  &quot;;
			}
			else {
				zeichen = zeichenwert3;
				cout &lt;&lt; zeichen &lt;&lt; &quot; &quot;;
			}
		}
		cout &lt;&lt; endl;
	}

	system(&quot;pause&quot;);
	return 0;
}
</code></pre>
<p>Da ich noch ziemlich am Anfang bin, was programmieren angeht, wollte ich mal fragen ob es vielleicht kürzere/einfachere Wege gibt als meinen. Vielleicht wo man Dinge einsparen könnte usw... zu Lernzwecken halt. <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="🙂"
    /></p>
<p>Herzlichen Dank für ihre Aufmerksamkeit ... <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/2072587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072587</guid><dc:creator><![CDATA[user369]]></dc:creator><pubDate>Thu, 02 Jun 2011 22:48:31 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur Optimierung von Programm on Thu, 02 Jun 2011 22:55:42 GMT]]></title><description><![CDATA[<p>zeichenwert3 könntest du weglassen (ist redundant) und eventuell nur eine Schleife verwenden, die von 30 bis 129 zählt (die Zeilenwechsel werden dann per <code>if(zeichen%10==0){...}</code> realisiert).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072591</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072591</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 02 Jun 2011 22:55:42 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur Optimierung von Programm on Thu, 02 Jun 2011 23:25:21 GMT]]></title><description><![CDATA[<p>Als Anregung eine etwas kürzere Variante:</p>
<pre><code class="language-cpp">cout &lt;&lt; &quot;    0 1 2 3 4 5 6 7 8 9&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;  +--------------------&quot; &lt;&lt; endl;
    for (unsigned line = 3; line &lt;= 12; ++line)
      {
        cout &lt;&lt; setw(2) &lt;&lt; line &lt;&lt; '|';
        for (unsigned column = 0; column &lt; 10; ++column)
          {
            char character = line * 10 + column;
            if (character &lt; 32 or character &gt; 126) character = ' ';
            cout &lt;&lt; ' ' &lt;&lt; character;
          }
        cout &lt;&lt; '\n';
      }
</code></pre>
<p>Diese zeichnet sich vor allem durch Benutzung des stream-manipulators <a href="http://www.cplusplus.com/reference/iostream/manipulators/setw/" rel="nofollow">setw</a> aus, durch Weglassen der schon angesprochenen Redundanzen und durch Benutzung wesentlich aussagekräftigerer Variablennamen (wenn auch noch nicht optimal). Außerdem mochte ich deinen Einrückungsstil nicht <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="😃"
    /> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072597</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072597</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 02 Jun 2011 23:25:21 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur Optimierung von Programm on Fri, 03 Jun 2011 07:04:15 GMT]]></title><description><![CDATA[<p>Bei deiner (user369) Variante könntest du die Variablen lokaler definieren. Alle Variablen am Anfang des Scopes zu definieren ist ein Relikt aus C.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072647</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Fri, 03 Jun 2011 07:04:15 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur Optimierung von Programm on Fri, 03 Jun 2011 08:08:35 GMT]]></title><description><![CDATA[<p>Okay, ich danke für die Antworten.<br />
Ich werde mal probieren, das umzusetzen. <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="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2072670</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2072670</guid><dc:creator><![CDATA[user369]]></dc:creator><pubDate>Fri, 03 Jun 2011 08:08:35 GMT</pubDate></item></channel></rss>