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.
Write Fibonacci series up to 8 numbers.
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 :
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.
Fibonacci series c program
int fibonacci(int n)
printf("Input the number of terms for Fibonacci Series:");
printf("\nFibonnaci Series is as follows\n");
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.
=> n = 5
6. we call recursive function by passing number
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.