Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

int func2(int m, int n) { if( n ==0 ) return0; else return m +func2(m, n-1); } a

ID: 3615747 • Letter: I

Question

int func2(int m, int n) {
    if( n ==0 )
          return0;
    else
          return m +func2(m, n-1);
}


a) What is the limiting condition of the code above?
a. n >= 0       b. m > n
c. m >= 0      d. n >m

b) What is the output of func2(2,3)?
a. 2     b. 3
c. 5     d. 6

c) Which of the following statements about the code above is alwaystrue?
a. func2(m,n) = func2(n,m) for m > = 0
b. func2(m,n) = m * n for n >= 0
c. func2(m,n) = m + n for n >= 0
d. func2(m,n) = n * m for n >= 0

*feel free to answer in multiple posts

Explanation / Answer

Part B. The answer is 6. Why? When you call func2(2,3) we return 2 + func2(2,2) = 2 + 2 + func2(2,1) =2 + 2 + 2 + func2(2,0) = 2 + 2 + 2 + 0 = 2 + 2 + 2 = 3(2) =6. Part C. It could either be B or D because order doesn't matterin multiplication. Okay so as in the previous example we saw that we added #2 3times which is the same thing as saying 2 * 3 = 6. Part C. It could either be B or D because order doesn't matterin multiplication. Okay so as in the previous example we saw that we added #2 3times which is the same thing as saying 2 * 3 = 6.