Please write your name and lab section letter at the top of the page.
Consider the following iterative program that is supposed
to compute the product of m and n using addition (no multiplications
are allowed!)
public int mpy(int m, int n) { // m and n must be nonnegative
int i = 0; /* line 1 */
int ans = ? ; /* line 2 */
while (i != n) { /* line 3 */
i = i + 1;
ans = ???? ; /* line 4 */
}
return ans;
}
ans be initialized at line 1?
ans be modified at line 4?
while loop
at line 3? Your answer must be a predicate (Boolean-valued expression).
int i = 1;
how would you initialize ans at line 2?