Dry run the following code and draw the tree to show how recursion is solved. On writing only
output you will get zero number.
int fun(int a, int b)
{
if (b == 0)
return 0;
if (b % 2 == 0)
return fun(a + a, b/2);
return fun(a + a, b/2) + a;
}
int main()
{
cout << fun(4, 3) ;
return 0;
}
The answer to your question is provided in the image:
Comments
Leave a comment