– Assuming n > 2, what value does the following function compute for odd n?function f (int n){if (n equals 1){ return 1}if (n equals 2){ return f(n-1) + n/2}return f(n-2) + n;}
A. 1 + 2 + 3 + 4 + … + n
B. 1 + 3 + 5 + 7 + … + n
C. n/2 + (1 + 3 + 5 + 7 + … + n)
D. 1 + (1 + 3 + 5 + 7 + … + n)
Answer:B
– Assuming n > 2, what value does the following function compute for odd n?function f (int n){if (n equals 1){ return 1}if (n equals 2){ return f(n-1) + n/2}return f(n-2) + n;}
A. 1 + 2 + 3 + 4 + … + n B. 1 + 3 + 5 + 7 + … + n C. n/2 + (1 + 3 + 5 + 7 + … + n) D. 1 + (1 + 3 + 5 + 7 + … + n)
Explanation: Given that n is odd and >2, The list generate is 1+3+5+7…+n