In C create fibonnaci sequence with a recursive function tha
In C++ create fibonnaci sequence, with a recursive function that only takes in one parameter and prints the sequence.
In C++ create fibonnaci sequence, with a recursive function that only takes in one parameter and prints the sequence.
Solution
Answer:
C++ Code :
#include<iostream>
using namespace std;
int fibonacci(int input)
{
if((input==1)||(input==0))
{
return(input);
}
else
{
return(fibonacci(input-1)+fibonacci(input-2));
}
}
int main()
{
int input,i=0;
cout<<\"Enter the number of terms for fibonacci series:\";
cin>>n;
cout<<\"\ The fibonacci series is as given below :\ \";
while(i<input)
{
cout<<\" \"<<fibonacci(i);
i++;
}
return 0;
}
Output :
Enter the number of terms for fibonacci series:6
The fibonacci series is as given below : 0 1 1 2 3 5
