title: How to extract prime numbers from a fibonacci series in C program?
body: <p>My University exam had a question on generating the FIB series and extracting the PRIME numbers from the result. I wrote the following code and I get the correct result. However, I am sure my code is not clean.. Can someone help me with writing a new code or edit mine and make it clean?</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      int t1 = 0, t2 = 1, nextTerm = 0, n, i, position = 2, primeNumber[10], init = 2, count = 0;
      printf(&quot;Input N= &quot;);
      scanf(&quot;%d&quot;, &amp;n);
  
      printf(&quot;Fibonacci List: %d %d &quot;, t1, t2);
      nextTerm = t1 + t2;
  
      while (nextTerm &lt;= n)
      {
          printf(&quot;%d &quot;, nextTerm);
          primeNumber[position] = nextTerm;
          position++;
          t1 = t2;
          t2 = nextTerm;
          nextTerm = t1 + t2;
      }
  
      printf(&quot;\nPrime numbers are &quot;);
      position = 3;
      i = 1;
      init = 0;
  
      for (init = 1; init &lt;= 7; init++)
      {
          for (i = 1; i &lt;= primeNumber[position]; i++)
          {
              if (primeNumber[position] % i == 0)
              {
                  count++;
              }
          }
          if (count == 2)
          {
              printf(&quot;%d &quot;, primeNumber[position]);
          }
          count = 0;
          position++;
      }
      return 0;
  }
  </code></pre>