title: In C, computing an equation using user input values is not giving the expected result?
body: <p>I am doing an assignment for my class but I am stuck. The assignment is to:</p>
  
  <p>Write a recursive program to precompute Fibonacci numbers and store them in an array. Fibonacci formula is Fib(0) = 1, Fib(1) = 1 and Fib(i) = Fib(i − 1) + Fib(i − 2). Store the ith Fibonacci number at index i. Have a loop to read i and print i and ith Fibonacci number. Use −1 to quit the loop. My output is wrong but I don't know how to fix it. I have been trying for a while now but I just couldn't pinpoint my mistake.</p>
  
  <p>My code is     </p>
  
  <pre><code>#include &lt;stdio.h&gt;  
  double Fib[50]; //globally declared 
  int fib(int i)
  {               
      for(i=0; i&lt;50; i++) //loop to scan 
      {   
          scanf("%lf", &amp;Fib[i]); //scan and store numbers in an array
          if (Fib[i]==-1) //i =-1 will end loop
              break;
      }       
      Fib[i]= Fib[i-1]+Fib[i-2];//formula     
      if(Fib[i]==0||Fib[i]==1) //i=0 and i=1 will print 1
          Fib[i]=1;
      else if(i&gt;1) //performs the operation with the formula
          printf("%d  %lf\n", i, Fib[i]);
  }   
  int main()
  {
      int i=0;
      fib(i); 
  return 0;    
  }
  Expected result:
  user input: 4 10 20 15 5 -1
  output:
  4 5.000000
  10 89.000000
  20 10946.000000
  15 987.000000
  5 8.000000  
  
  My output:
  5  20.000000
  </code></pre>