C++ code: Make a recursive function which displays the fibonacci series before a number that is entered by the user. Requirements: No global declarations Test run in main Diagram: Also draw diagram to show how the recursive call is working
The Answer to the Question
is below this banner.
Can't find a solution anywhere?
NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?
Get the Answers Now!You will get a detailed answer to your question or assignment in the shortest time possible.
Here's the Solution to this Question
using namespace std;
int FibonacciSeries(int n)
{
if((n==1)||(n==0)) return(n);
else return(FibonacciSeries(n-1)+FibonacciSeries(n-2));
}
int main()
{
int num , i=0;
cout << "Enter a number (>=0): "; cin >> num;
cout << "\nThe Fibonnaci Series : ";
while(FibonacciSeries(i) <= num)
{
cout << " " << FibonacciSeries(i);
i++;
}
return 0;
}