<?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[Was bewirkt der (typ) der Variablen hier ??]]></title><description><![CDATA[<p>Hab Folgendes zur Annäherung an die Kreiszahl Pi:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
using namespace std;

int main()
{
    int max;
    double pi=1.0, n=2;
    cin&gt;&gt;max;

   while(n&lt;max)
   {
                pi=pi*((n/(n-1))*(n/(n+1)));
                n+=2;
   }             

   cout&lt;&lt;pi*2&lt;&lt;endl;

   cin.get();
   cin.get();
}
</code></pre>
<p>So wie sie da steht passt es ja.<br />
Wenn ich aber der Variable n den typ 'int n=2' gebe, statt 'double n=2', kommt als Ergebnis immer nur Null.<br />
Woran liegt das eigentlich, was bewirkt es ??</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/271259/was-bewirkt-der-typ-der-variablen-hier</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 14:58:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/271259.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 25 Jul 2010 18:13:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Was bewirkt der (typ) der Variablen hier ?? on Sun, 25 Jul 2010 18:13:42 GMT]]></title><description><![CDATA[<p>Hab Folgendes zur Annäherung an die Kreiszahl Pi:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
using namespace std;

int main()
{
    int max;
    double pi=1.0, n=2;
    cin&gt;&gt;max;

   while(n&lt;max)
   {
                pi=pi*((n/(n-1))*(n/(n+1)));
                n+=2;
   }             

   cout&lt;&lt;pi*2&lt;&lt;endl;

   cin.get();
   cin.get();
}
</code></pre>
<p>So wie sie da steht passt es ja.<br />
Wenn ich aber der Variable n den typ 'int n=2' gebe, statt 'double n=2', kommt als Ergebnis immer nur Null.<br />
Woran liegt das eigentlich, was bewirkt es ??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931544</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931544</guid><dc:creator><![CDATA[diadoros]]></dc:creator><pubDate>Sun, 25 Jul 2010 18:13:42 GMT</pubDate></item><item><title><![CDATA[Reply to Was bewirkt der (typ) der Variablen hier ?? on Sun, 25 Jul 2010 18:18:30 GMT]]></title><description><![CDATA[<p>Was ergibt</p>
<pre><code class="language-cpp">cout&lt;&lt;25/3&lt;&lt;endl;
</code></pre>
<p>?<br />
Darum ist n/(n+1)==0</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931546</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931546</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 25 Jul 2010 18:18:30 GMT</pubDate></item><item><title><![CDATA[Reply to Was bewirkt der (typ) der Variablen hier ?? on Sun, 25 Jul 2010 18:22:51 GMT]]></title><description><![CDATA[<p>Der Operator / ist überladen. Das heißt, je nach Operanden ist das entweder eine Ganzzahldivision oder eine Division auf Fließkommazahlen. Das Ergebnis einer Ganzzahldivision ist wieder eine Ganzzahl.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931553</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931553</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 25 Jul 2010 18:22:51 GMT</pubDate></item><item><title><![CDATA[Reply to Was bewirkt der (typ) der Variablen hier ?? on Sun, 25 Jul 2010 18:30:05 GMT]]></title><description><![CDATA[<p>Achso. <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="😃"
    /> Sry, war 'ne blöde Frage. Danke, dass ihr trotzdem geantwortet habt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1931557</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1931557</guid><dc:creator><![CDATA[diadoros]]></dc:creator><pubDate>Sun, 25 Jul 2010 18:30:05 GMT</pubDate></item></channel></rss>