Consider the following function fpp.
def foo(m):
if m == 0:
return(0)
else:
return(m+foo(m-1))
Which of the following is correct?
The function always terminates with f(n) = factorial of n
The function always terminates with f(n) = n(n+1)/2
The function terminates for nonnegative n with f(n) = factorial of n
The function terminates for nonnegative n with f(n) = n(n+1)/2
The correct answer is: The function terminates for nonnegative n with f(n) = n(n+1)/2
Comments
Leave a comment