1.

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); } }

Answer»

Given n = 43629, x = 3, y = 4

Stepnumxynum<10zz%2return
1.4362934false9136+Mystery (4362,5,4)
2436234false206+ Mystery (436+3,4)
3.43634false6018+ Mystery (43,3,4)
4.4334false3112+ Mystery (4,3,4)
5.434

Step 5 return 4

Step 4 returns 12+4 =16

Step 3 returns 18+16 =34

Step 2 returns 6+34 = 40

Step 1 returns 36+40 = 76



Discussion

No Comment Found

Related InterviewSolutions