InterviewSolution
Saved Bookmarks
| 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
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 |
|||||||||||||||||||||||||||||||||||||||||||||||||