**Fibonacci Series is a simple program** which is implemented using a different method in c.

In this tutorial we are going to learn recursion in c, what is **Fibonacci series, Fibonacci series algorithm, Fibonacci series in c.**

**What is Fibonacci :**

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

**Fibonacci series logic**

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.

**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

We implement the Fibonacci series program in c in two ways as:

**First is Fibonacci series using for Loop****Second is Fibonacci series using While Loop****Fibonacci series using recursion**

Let’ss see methods one by one

**Fibonacci series using for Loop **

This is the first method to print the Fibonacci series. In this, we use the for loop to iterate number to range up to which we want to print the Fibonacci series.

## Fibonacci series using for loop

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <stdio.h> int main() { int i, n, t1 = 0, t2 = 1, nextTerm; printf("Enter the number of terms: "); scanf("%d", &n); printf("Fibonacci Series: "); for (i = 1; i <= n; ++i) { printf("%d, ", t1); nextTerm = t1 + t2; t1 = t2; t2 = nextTerm; } return 0; } |

**Output:**

**Fibonacci series using while Loop **

This is the second method to print the Fibonacci series. In this, we use the while loop to iterate number to range up to which we want to print the Fibonacci series.

## C program for Fibonacci Series using while loop

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include<stdio.h> int main() { int n,i,a,b,c; printf("Enter a number: "); scanf("%d",&n); i=1; a=0; b=1; while(i<=n) { printf("%d ",a); c = a + b; a = b; b = c; i++; } return 0; } |

**Output:**

**Fibonacci Series using recursion**

This is the third method to print the Fibonacci series.

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

**Recursion in c :**

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

## C program for Fibonacci Series using recursion

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 :**

## Leave a Reply