Fibonacci series by recursion in C++ by R4R Team

Fibonacci series :
A series in which each element are the sum of previous two elements is known as Fibonacci series.

Example-
0 1 1 2 3 5 8 13 ................

program:

#include < iostream>

using namespace std;
class r4r
{
public:
int fibo(int n,int a,int b)
{
if(n==2)
return 0;
cout<< a+b<<" ";
fibo(n-1,b,a+b);
}
};
int main()
{
r4r obj;
int n;
cout<<"Enter number of term"<< endl;
cin>>n;
cout<<"0 1 ";
obj.fibo(n,0,1);
return 0;
}


output-

Enter number of terms
7
0 1 1 2 3 5 8 13




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!