title: How to extract prime numbers from a fibonacci series in C++?
body: <p>Please help my code is as follows. I have found out the Fibonacci series within a range successfully but I am finding it difficult to extract the prime numbers from the Fibonacci series. There seems to be a lot of bugs in the prime number part. Please help. Thanks</p>
  
  <pre><code>#include&lt;iostream.h&gt;
  #include&lt;conio.h&gt;
  
  void main()
  {
    clrscr();
    int n, c, first = 0, second = 1, next, flag;
  
    cout &lt;&lt; "Enter the number of terms of Fibonacci series you want" &lt;&lt; endl;
    cin &gt;&gt; n;
  
    cout &lt;&lt; "First " &lt;&lt; n &lt;&lt; " terms of Fibonacci series are :- " &lt;&lt; endl;
  
    for (c = 0; c &lt; n; c++)
    {
      if (c &lt;= 1)
        next = c;
      else
      {
        next = first + second;
        first = second;
        second = next;
      }
      cout &lt;&lt; next &lt;&lt; endl;
      for (int j = 2; j&lt;next; j++)
      {
        if (next%j == 0)
        {
          flag++;
        }
        if (flag == 0)
        {
          cout &lt;&lt; "Prime numbers are" &lt;&lt; next &lt;&lt; "\t";
        }
      }
      getch();
    }
  }
  </code></pre>