Fibonacci Series

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 Fibonacci series program in c in two ways as:

1. Using for Loop
2. Using While Loop
3. By using recursion

Using for Loop

This is first method to print the Fibonacci series.

In this we use the for loop to iterate number till range up to which we want to print the Fibonacci series.

Write a program to print the Fibonacci series using for loop

Write a program to print the Fibonacci series using for loop

C

Output:

Enter the number up to which you want to print series :

5

The series is:

0 1 1 2 3 5 8

Using while Loop

This is second method to print the Fibonacci series.

In this we use the while loop to iterate number till range up to which we want to print the Fibonacci series.

Write a program to print the Fibonacci series using while loop

Write a program to print the Fibonacci series using while loop

C

Output:

Enter the number up to which you want to print series :

5

The series is:

0 1 1 2 3 5 8

Using recursion

This is third method to print the Fibonacci series.

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

Write a program to print the Fibonacci series using recursion

C

Output:-

Enter the number up to which you want to print series :

5

The series is:

0 1 1 2 3 5 8

This are fibonacci series logic.