C++ Program to obtain Fibonacci series using recursion [DEVCPP/GCC]


PROGRAM

//Program to get the Fibonacci series using recursion 

# include <iostream>

using namespace std;

int fib(int n)
{
if(n==1||n==2)     //base condition
{
return 1;
}
else
        {
return fib(n-1)+fib(n-2);
         }
}

int main()
{
int i,num;
cout<<"ENTER THE NUMBER UPTO WHICH YOU WANT THE FIBBONACI SERIES TO          BE PRINTED:\n";
cin>>num;
cout<<"OUTPUT:\n";

for(i=1;i<=num;i++)
{
cout<<fib(i)<<" ";
}

return 0;
}

OUTPUT

C++ Program to obtain Fibonacci series using recursion with output

Share this

Related Posts

FIND US ON FACEBOOK!