#include<iostream>
using
namespace std;
int
fibo(int n); //function declaration
int
main()
{
int n,i; // declaring the variables
cout<<"Enter the total elements in the series : ";
cin>>n;
cout<<"\nThe Fibonacci series is:\n";
for(i=0;i<n;i++)
{
cout<<fibo(i)<<"
";
}
return 0;
}
int
fibo(int n)
{
if(n==0)
// if n=0 ,directly it will show
the output
{
return
0;
}
else
if(n==1) // if n=1 ,directly it will
show the output
{
return 1;
}
else
{
return fibo(n-1)+fibo(n-2);
// recursion
method
}
}
code :
OUTPUT :
Try
it :
Write
a program to print the Fibonacci series without using recursion method.