Fibonacci Series Using Recursion in C++
Q. Write a C++ program for Fibonacci Series using Recursion.
#include <iostream>
using namespace std;
int fibon(int n)
{
if (n == 0 || n == 1)
return n;
else
return (fibon(n-1) + fibon(n-2));
}
int main()
{
int n;
cout << "Enter the number:";
cin >> n;
cout << "Fibonacci series terms are: ";
for (int i = 0; i < n; i++)
{
cout << fibon(i) << " ";
}
return 0;
}
Q. Write an algorithm to Fibonacci Series using Recursion.
1. Start 2. Read integer `n` from the user. 3. Define a recursive function `fibon(int n)` that returns the nth Fibonacci number: - If `n == 0`, return 0. - Else if `n == 1`, return 1. - Else return `fibon(n-1) + fibon(n-2)`. 4. Print "Fibonacci series terms are: " 5. For `i` from 0 to `n-1` do: - Call `fibon(i)` - Print the returned value followed by a space. 6. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com