**Fibonacci series using recursion** is simple program which is implemented using recursion in c.

In this tutorial we are going to leans recursion in c, **Fibonacci series logic, Fibonacci series algorithm, Fibonacci series using recursion.**

**Recursion in c :**

Its is a process where function calls itself directly or indirectly.

**what is Fibonacci :**

Fibonacci is a series of numbers starting from 0 and adding with two numbers before it.

**Fibonacci series c**

Fibonacci series is a collection or set of the numbers starting with zero or one, followed by the sum of two preceding numbers.

consider Fibonacci series till **N** which is implemented as **0,1,(0+1),(0+2)…. N.**

**Fibonacci series logic**

In this, we recursively call the function calculating the series to range up to which we want to print the Fibonacci series.

**Example :**

Write Fibonacci series up to 8 numbers.

0,1,1,2,3,5,8,13.

we calculated this series as first two number as 0 and 1 , 0+1 => 1, 1+2=>3 ,3+2=>5,5+3=>8,8+5=>13

**Fibonacci algorithm :**

1. Start

2. Write a recursive function to find Fibonacci series

3. write main

4. Declare variable.

5. Take a number from user

6. Pass Number to function

7. Find Fibonacci series in function

8. Print Fibonacci series.

9. End

## Fibonacci series c program

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include<stdio.h> int fibonacci(int n) { if((n==1)||(n==0)) { return(n); } else { return(fibonacci(n-1)+fibonacci(n-2)); } } int main() { int n,i=0; printf("Input the number of terms for Fibonacci Series:"); scanf("%d",&n); printf("\nFibonnaci Series is as follows\n"); while(i<n) { printf("%d ",fibonacci(i)); i++; } return 0; } |

**Output :**

**Explanation :**

**1. Include header files in program.**

**2. Define a recursion function for Fibonacci series.**

**3. Write a main function **

**4. Declare the variables.**

i => temporary variable

n => to store number

**5. Take input number from user.**

scanf(“%d”,&n);

=> n = 5

**6. we call recursive function by passing number**

while(i<n)

**At iteration 1 :**

i=0 , 0 < 5 this condition is true and while loop executed.

pritf(“%d “,fibonacci(i)); => call to recursive function

**call 1 :**

if((n==1)||(n==0)) this condition false and else executed.

return(fibonacci(n-1)+fibonacci(n-2)) => it will add two previous numbers and return to main

and prints Fibonacci number

pritf(“%d “,fibonacci(i)) => 0

**7. and while loop executed again with value i=1**

**8. this process continues till value of i = 5**

**9. After while we have Fibonacci series printed.**

**Recommended posts **

## Leave a Reply