The following function magicfun( ) is a part of some class. What will the function magicfun( ) return, when the value of n=7 and n=10, respectively? Show the dry run/working:
int magicfun( int n)
{
if ( n= = 0)
return 0;
else
return magicfun(n/2) * 10 + (n % 2);
}
(i) when n=7
OUTPUT :
magicfun(7) magicfun(3) * 10 + 1
magicfun(1) *10 + 1
magicfun(0) *10 + 1
0
= 111
(ii) when n=10
OUTPUT :
magicfun(10) magicfun(5) * 10 + 0
magicfun(2) *10 + 1
magicfun(1) *10 + 0
magicfun(0) *10 + 1
0
= 1010