Question

Write the output of the following function assuming it was called with the given function call a. Call: fun(4, 10); fo void fun (int a, int b) cout << b a << endl; if(a >= b) { 나 cout < boo\n; return; fun(a 1, b 1); cout << a << endl;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Output :

6
4
2
0
boo
-2
boo
-4
boo
-6
boo
-8
boo
-10
boo
-12
boo
-14
Indefinite loop

It is a recursive function and there is no base condition to stop the recursive call . So indefinite loop will execute.

void fun(int a,int b)
{
cout<<b-a<<endl;
if(a >= b)
{
  cout<<"boo\n";
}
fun(a+1,b-1); //recursive call
cout<<" "<<a<<endl;
}
int main() {
fun(4,10); //function call
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write the output of the following function assuming it was called with the given function call...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following C++code snippet and what is the output of this program? # include<iostream> using...

    Consider the following C++code snippet and what is the output of this program? # include<iostream> using namespace std; void arraySome (int[), int, int); int main () const int arraysize = 10; int a[arraysize]-1,2,3,4,5, 6,7,8,9,10 cout << "The values in the array are:" << endl; arraySome (a, 0, arraySize) cout<< endl; system ("pause") return 0; void arraySome (int b[], int current, int size) if (current< size) arraySome (b, current+1, size); cout << b[current] <<""; a) Print the array values b) Double...

  • Use only C++ for all function Introduce a call-by-value function that computes the volume of a...

    Use only C++ for all function Introduce a call-by-value function that computes the volume of a box. Hint: Length, width, and height of a box is needed. Introduce a call-by-reference function with void output. that computes the square of an integer. Please double check the value of the function input before and after function call. Introduce a call-by-pointer function with void output. that computes the square of an integer. Please double check the value of the function input before and...

  • 6. Please provide step by step and concepts explanation. Thank you ! What is the output...

    6. Please provide step by step and concepts explanation. Thank you ! What is the output of the following program? #include <iostream> using namespace std; int fun (int p 2, int q = 3) return p+ qi int main (void) cout < fun (O +fun (1) + fun (1, 2) <<endl; return 0; 6 O 8 10 O 12

  • C++ output 6) What is the exact output of the following program? #include <iostream> using namespace...

    C++ output 6) What is the exact output of the following program? #include <iostream> using namespace stdi void zolo(int &a, int sb) int main int x = 5, y =8; zolo(x,y)i cout << "x " << x << endl ; cout << "y = "" << y << endl ; return o: void zolo(int &a, int &b) int v1 = b + a; ' int v2 = b-a; 3 a=v1;13

  • QUESTION 26 Given the following function: int secret(int num, int m) inti, prod=1; if (m=0) return...

    QUESTION 26 Given the following function: int secret(int num, int m) inti, prod=1; if (m=0) return 1: - for (i=0; i<m; i++) { prod = prod * num; } return prod; What is the output for this function call? cout << secret(10,6);

  • C++ What output does the following program produce? int getValue(int a, int b, int n); int...

    C++ What output does the following program produce? int getValue(int a, int b, int n); int main() cout << getValue(1, 7, 7) << endl; return 0; } // end main int getValue(int a, int b, int n) int returnValue = 0; cout << "Enter: a = " < a << " b = " << b << endl; int c = (a + b)/2; if (C* C <= n) return value = c; else returnValue = getValue(a, C-1, n); cout...

  • 5. (7 pts) What wil display on the output screen after following program is executed? includeciostream...

    5. (7 pts) What wil display on the output screen after following program is executed? includeciostream using namespace std int b 40 int A function(int a) int main (void) int c 7, b 15 cout<cA function (e) <cendla return 6 int A function (int a) int i cout<<b<<endl; if (a>-0) else return i i-ai i--ai Ans5 6. (7 pts) Show what will appear on the output screen after the following program is executed tincludeciostream> using namespace std; void A function...

  • 81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5...

    81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5 );                    int BoxVolume(int length = {1}, int width = {1}, int height = {1});                                                     T__   F__                                                                     82. The following function is implemented to swap in memory the          argument-values passed to it:         void swap(int a, int b)                   {           int temp;             temp = a;             a = b;             b = temp;        ...

  • Id: 40100885 in c++ output text please thanks! what is the output values printed by the...

    Id: 40100885 in c++ output text please thanks! what is the output values printed by the following code? You need to explain step by step how each printed value is calculated. #include <iostream> using namespace std; int m = 0; void SampleMethod (int); int SampleMethod(); void increase(); int main() { int j = 9; SampleMethod(j); cout << j<<endl; return 0; w Y == void SampleMethod(int i) { if (j%2 1) cout << SampleMethod() <<endl; else cout << j << "...

  • IV. Function Tracing (20 points) Trace the following program. Show llof your work and the ound...

    IV. Function Tracing (20 points) Trace the following program. Show llof your work and the ound he output in the work including labeled boxes for user-defined functions, calculations, and the output in designated spaces. You should draw a box for each variable and show value updates d the output, Show all of your #include <iostream» using namespace std; void mickey (int sa, int b, int &c) void minnie(int u, int &v, int w); void pluto (int m, int n, int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT