title: Fibonacci series in C++
body: <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      int num1 = 0;
      int num2 = 1;
      int num_temp;
      int num_next = 1;
      int n;
      cin &gt;&gt; n;
      for (int i = 0; i &lt; n; i++){
          cout &lt;&lt; num_next &lt;&lt; "  ";
          num_next = num1 + num2;
          num1 = num2;
          num_temp = num2;
          num2 = num_next - num1;
          num1 = num_temp;
      }
      return 0;
  }
  </code></pre>
  
  <p>I have to output the first "n" fibonacci numbers however I think there is some problem in logic.. I can't find out what am I doing wrong. The first 3 or 4 elements are correct but then a problem occurs...</p>
  
  <p>EXPECTED:<br>
  For <code>n=9</code></p>
  
  <blockquote>
    <p>0, 1, 1, 2, 3, 5, 8, 13, 21</p>
  </blockquote>
  
  <p>Actual:</p>
  
  <blockquote>
    <p>1  1  1  1  1  1  1  1  1</p>
  </blockquote>