Answer to Question #305392 in C++ for Olivia

Question #305392

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


1
Expert's answer
2022-03-03T09:59:48-0500
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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog