<?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 zu return]]></title><description><![CDATA[<p>Hallo,</p>
<p>also ich will hier die faktorielle einer zahl berechnen:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;

using std::cin;
using std::endl;
using std::cout;

int fact(int);

int zahl = 0;

int main()
{
	cin &gt;&gt; zahl;

	fact(zahl);

	cout &lt;&lt; fact(zahl) &lt;&lt; endl;

	return 0;

}

int fact(int a)
{
	if (a == 0)
	{
		return 1;    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	}

	else
	{
		return a * fact(a-1);
	}

}
</code></pre>
<p>Funktioniert soweit auch alles, was mir dabei nur unklar ist warum bei der if abfrage ich return 1 zurückgeben muss und nicht return 0?</p>
<p>kann mir das wer erklären?</p>
<p>danke &amp; lg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/251037/frage-zu-return</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 18:52:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/251037.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 Sep 2009 12:57:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu return on Mon, 28 Sep 2009 12:57:21 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>also ich will hier die faktorielle einer zahl berechnen:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;

using std::cin;
using std::endl;
using std::cout;

int fact(int);

int zahl = 0;

int main()
{
	cin &gt;&gt; zahl;

	fact(zahl);

	cout &lt;&lt; fact(zahl) &lt;&lt; endl;

	return 0;

}

int fact(int a)
{
	if (a == 0)
	{
		return 1;    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	}

	else
	{
		return a * fact(a-1);
	}

}
</code></pre>
<p>Funktioniert soweit auch alles, was mir dabei nur unklar ist warum bei der if abfrage ich return 1 zurückgeben muss und nicht return 0?</p>
<p>kann mir das wer erklären?</p>
<p>danke &amp; lg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1785393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785393</guid><dc:creator><![CDATA[buzz_lightzyear]]></dc:creator><pubDate>Mon, 28 Sep 2009 12:57:21 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu return on Mon, 28 Sep 2009 13:00:14 GMT]]></title><description><![CDATA[<p>Probier es aus, und du wirst es wissen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1785395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785395</guid><dc:creator><![CDATA[zwutz]]></dc:creator><pubDate>Mon, 28 Sep 2009 13:00:14 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu return on Mon, 28 Sep 2009 13:06:09 GMT]]></title><description><![CDATA[<p>Die Fakultät von 0 ist 1.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1785401</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785401</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 28 Sep 2009 13:06:09 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu return on Mon, 28 Sep 2009 13:15:55 GMT]]></title><description><![CDATA[<p>Waere ja auch bloed, wenn ich mir so viel Arbeit mit dem Multiplizieren gemacht habe und dann alles mit 0 mal genommen wird. Dann kommt immer 0 raus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1785409</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1785409</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Mon, 28 Sep 2009 13:15:55 GMT</pubDate></item></channel></rss>