Write a c program to print the Fibonacci series up to n terms.

In Fibonacci series, the first and second term are 0 and 1 respectively and every nth term is the sum of (n-2)th term and (n-1)th term.

Example: 0, 1, 1, 2, 3, 5, 8, 13 ,etc.

For this, we will assume a=0 as first and b=1 as the second term and will calculate the third term by a+b.

After outputting the third term, we will update a=b and b=c and the fourth term will be a+b.

we will repeat the process until the nth term.

Output

Fibonacci series using Recursion

Fibonacci series can also be implemented using recursion.

The recursion method will return the nth term by computing the recursive(n-2)+recursive(n-1).

Since the recursive method only returns a single nth term we will use a loop to output each term of the series.

Output

Leave a Reply

Close Menu