Fibonacci Series Using Recursion
Here you will learn to create a C++ program for Fibonacci series using recursion.
Fibonacci Series meaning
Fibonacci series is the list of numbers, in which each numbers is the sum of last two previous numbers, it starts from 0 and 1.
For example:
0, 1, 1, 2, 3, 5, 8, 13, 21……..
Example of 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 | #include <iostream> using namespace std; int count=0,a=1,b=1,n,c,f; febo(int a,int b) { if(count==n-2) return c; else { count++; c=a+b; cout<<"\t"<<c; febo(b,c); } } int main() { int sum; int febo(int,int); cout<<"\nEnter the number of terms : "; cin>>n; cout<<"\n"<<a<<"\t"<<b; c=febo(a,b); } |
Output
Enter the number of terms : 15
Fibonacci Series: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
Check out our other C++ programming Examples