I am learning about recursion in C. My problem is: Print 80 first Fibonacci numbers (using recursion)
Here is the book's code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
long long f[100];
long long fib(int n)
{
if (n<2) return 1;
if (f[n]>0) return f[n];
f[n] = fib(n-1)+fib(n-2);
return f[n];
}
int main()
{
int i;
for (i = 0; i<= 80; i++) printf ("%lld \n", fib(i));
system ("pause");
return 0;
}
With this code, my program runs very fast and I immediately get 80 Fibonacci numbers.
However, when I delete the 10th line:
if (f[n] > 0) return f[n];
The program becomes very slow and it takes about 20 seconds to print all 80 numbers. Can anyone explain why? Thank you.

