Which of the following methods would properly compute the value of x % y (x mod y) recursively, assuming that x and y are not negative numbers?
A) public int recursiveMod(int x, int y)
{
If (x < y) return y;
Else return recursiveMod(x, y - x) ;
}
B) public int recursiveMod(int x, int y)
{
If (x == y) return 0;
Else return recursiveMod(x - y, y) + 1;
}
C) public int recursiveMod(int x, int y)
{
If (x < y) return x;
Else return recursiveMod(x - y, y) + 1;
}
D) public int recursiveMod(int x, int y)
{
If (x < y) return x;
Else return recursiveMod(x - y, y) ;
}
E) public int recursiveMod(int x, int y)
{
While (x > y)
X = x - y;
Return x;
}
Correct Answer:
Verified
Q12: A Koch snowflake of order = 1
Q13: What is wrong with the following recursive
Q14: Consider the following recursive sum method:
public int
Q15: Traversing a maze is much easier to
Q16: A recursive algorithm is superior to an
Q18: A recursive method without a base case
Q19: It always is possible to replace a
Q20: If one were to create a Towers
Q21: Recall the Towers of Hanoi recursive solution
Q22: Example Code Ch 12-2
Given the following recursive
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents