title: How to generate Fibonacci faster
body: <p>I am a CSE student and preparing myself for programming contest.Now I am working on Fibonacci series. I have a input file of size about some Kilo bytes containing positive integers. Input formate looks like  </p>
  
  <pre><code>3 5 6 7 8 0
  </code></pre>
  
  <p>A zero means the end of file. Output should like </p>
  
  <pre><code>2 
  5 
  8 
  13 
  21 
  </code></pre>
  
  <p>my code is </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int fibonacci(int n) {
    if (n==1 || n==2)
      return 1;
    else
      return fibonacci(n-1) +fibonacci(n-2);
  }
  int main() {
    int z;
    FILE * fp;    
    fp = fopen ("input.txt","r");    
    while(fscanf(fp,"%d", &amp;z) &amp;&amp; z) 
     printf("%d \n",fibonacci(z));
    return 0;
  }
  </code></pre>
  
  <p>The code works fine for sample input and provide accurate result but problem is for my real input set it is taking more time than my time limit. Can anyone help me out.</p>