# C - 斐波那契数列递归

## fibonacci recursion

```function fib(n) {
if (n === 1 || n === 0)
return n

return fib(n - 1) + fib(n - 2)
}
console.log('fib:', fib(9))		// [Log]: fib: 34
// Time complexity O(2^n)
// Space complexity O(n)
// Since fib(n-1) gets evaluated completely before fib(n-2), there will never be more than n levels of recursion.```

## fibonacci series recursion

```#include<stdio.h>
int main()
{
int first=0, second=1, i, n, sum=0;
printf("Enter the number of terms: ");
scanf("%d",&n);
//accepting the terms
printf("Fibonacci Series:");
for(i=0 ; i<n ; i++)
{
if(i <= 1)
{
sum=i;
}
//to print 0 and 1
else
{
sum=first + second;
first=second;
second=sum;
//to calculate the remaining terms.
//value of first and second changes as new term is printed.
}
printf(" %d",sum)
}
return 0;
}```

## fibonacci using recursion

```int fib (int n) {
if (n < 2)
return 1;
return fib(n-1) + fib(n-2);
}```

## fibonacci series using recursion

```def fib (n):
if n == 0 or n ==1:
return n
else:
return fib(n-2) + fib(n-1)
#n = int(input("please enter a number  "))

n=10
for index,num in enumerate(range(n+1)):
print(f"F{index} :", fib(num))```