Q11. How to generate fibonacci sequence up to given nth number?

First we should know what fibonacci sequence is:

The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … n where the next number is found by adding up the two numbers before it. Similarly, the 8 is found by adding the two numbers before it 5 and 3, the 13 is found by adding the two numbers before it 8 and 5.

Using recursive function to generate Fibonacci series up to given nth number.

int fibonacci_series(int n)

{

if (n <= 2)

{

return 1;

}

else

{

return fib(n-1) + fib(n-2);

}

}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.