Output of recursion in C++
Not what you're looking for?
Consider the following function:
int Func(int x)
{
if(x == 0)
return 2;
else if(x == 1)
return 3;
else
return (Func(x - 1) + Func(x - 2));
}
What is the output of the following statements?
a. cout<<Func(0)<<endl;
b. cout<<Func(1)<<endl;
c. cout<<Func(2)<<endl;
d. cout<<Func(5)<<endl;
Purchase this Solution
Solution Summary
This posting contains output to following program in C++.
Solution Preview
Please see the attached file.
a. Calling func() with x=0.
Thus, The first condition of x=0 is satisfied. Function will return 0.
Output would be: 2
b. cout<<Func(1)<<endl;
Thus, The Second condition of x=1 is satisfied. Function will return 0.
Output would be: ...
Purchase this Solution
Free BrainMass Quizzes
C# variables and classes
This quiz contains questions about C# classes and variables.
Inserting and deleting in a linked list
This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.
C++ Operators
This quiz tests a student's knowledge about C++ operators.
Word 2010: Tables
Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.
Basic Networking Questions
This quiz consists of some basic networking questions.