Course Solutions Uncategorized (Solved) : Lesson 2 Consider Following Recursive Function Public Static Int Mystery Int Int B B 0 Ret Q30568881 . . . .

(Solved) : Lesson 2 Consider Following Recursive Function Public Static Int Mystery Int Int B B 0 Ret Q30568881 . . . .

 

lesson 2

Consider the following recursive function.

public static int mystery(int a, int b) { if (b == 0) return0;

if (b % 2 == 0) return mystery(a+a, b/2);

return mystery(a+a, b/2) + a; }

What are the values of mystery(2, 25) and mystery(3, 11)? Givenpositive integers a and b, describe what value mystery(a, b)computes. Answer the same question, but replace + with * andreplace return 0 with return 1. Solution: 50 and 33. It computesa*b. If you replace + with *, it computes a^b.

Expert Answer


An answer will be send to you shortly. . . . .

Leave a Reply

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

Related Post