OUTPUT 2019

The following function Mystery( ) is a part of some class. What will the function Mystery ( ) return when the value of num=43629, x=3 and y=4 respectively? Show the dry run/ working.

int Mystery( int num, int x, int y) 
{ 
	if(num<10) 
		return num; 
	else 
	{ 
		int z = num % 10; 
		if( z % 2 = = 0 ) 
			return z*x + Mystery( num/10,x,y);
		else 
			return z*y + Mystery( num/10,x,y); 
	} 
} 

Mystery ( 43629 , 3 , 4 )
9 * 4 + Mystery (4362, 3, 4)
2 * 3 + Mystery ( 436, 3, 4)
6 * 3 + Mystery ( 43, 3, 4)
3 * 4 + Mystery (4, 3, 4)
4
Final output: 4 + 12 + 18 + 6 + 36 = 76

This entry was posted in Output. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *