---------------------------------------------------------------------------------------------------------------------
Fibonacci Series With Recursion Try It🔻
---------------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int fibonacci(int n)
{
if((n==1)||(n==0))
{
return(n);
}
else
{
return(fibonacci(n-1)+fibonacci(n-2));
}
}
int main()
{
int n,i=0;
cout<<"Input the number of terms for Fibonacci Series : ";
cin>>n;
cout<<"\nFibonacci Series for the given number of terms : ";
while(i<n)
{
cout<<" "<<fibonacci(i);
i++;
}
return 0;
}
---------------------------------------------------------------------------------------------------------------------
OUTPUT Try It🔻
Fibonacci Series for the given number of terms : 0 1 1 2 3 5 8 13 21 34
Fibonacci Series With Recursion Try It🔻
---------------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int fibonacci(int n)
{
if((n==1)||(n==0))
{
return(n);
}
else
{
return(fibonacci(n-1)+fibonacci(n-2));
}
}
int main()
{
int n,i=0;
cout<<"Input the number of terms for Fibonacci Series : ";
cin>>n;
cout<<"\nFibonacci Series for the given number of terms : ";
while(i<n)
{
cout<<" "<<fibonacci(i);
i++;
}
return 0;
}
---------------------------------------------------------------------------------------------------------------------
OUTPUT Try It🔻
---------------------------------------------------------------------------------------------------------------------
Input the number of terms for Fibonacci Series : 10Fibonacci Series for the given number of terms : 0 1 1 2 3 5 8 13 21 34