0
Consider the following function fdef f(m): if m == 0: return(1) else: return(m*f(m-1)) Which of the following is correct?
a) The function always terminates with f(n) = n b) The function always terminates with f(n) = factorial of n c) The function terminates for non-negative n with f(n) = n d) The function terminates for non-negative n with f(n) = factorial of n
10 ответов
+ 2
It's a typical recursive function to compute factorials, but it doesn't take care of negative values. The answer would be d.
+ 4
Consider the following function f
def f(m):
if m == 0:
return(1)
else:
return(m*f(m-1))
Which of the following is correct?
The function always terminates with f(n) = n
The function always terminates with f(n) = factorial of n
The function terminates for non-negative n with f(n) = n
The function terminates for non-negative n with f(n) = factorial of n
tell a correct answer???
0
f(n)=factorial of n
0
ans is d
0
Consider the following function f.
def f(m):
if m == 0:
return(0)
else:
return(m+f(m-1))
Which of the following is correct?
The function always terminates with f(n) = n(n+1)/2
The function always terminates with f(n) = factorial of n
The function terminates for non-negative n with f(n) = n(n+1)/2
The function terminates for non-negative n with f(n) = factorial of n
Please tell me this program answer
0
Consider the following function h.
def h(n):
f = 0
for i in range(1,n+1):
if n%i == 0:
f = f + 1
return(f%2 == 1)
The function h(n) given above returns True for a positive number n whenever:
n is a multiple of 2
n is a composite number
n is a prime number
n is a perfect square
Tell me the above program answer
0
composite no.
0
def f(m):
if m == 0:
return(0)
else:
return(m+f(m-1))
Which of the following is correct?
The function always terminates with f(n) = n(n+1)/2
The function always terminates with f(n) = factorial of n
The function terminates for non-negative n with f(n) = n(n+1)/2
The function terminates for non-negative n with f(n) = factorial of n
0
0
def f(m):
if m == 0:
return(0)
else:
return(m+f(m-1))
Which of the following is correct?
Ans: The function terminates for non-negative n with f(n) = n(n+1)/2
0
def mys(m):
if m == 1:
return(1)
else:
return(m*mys(m-1))
Which of the following is correct?
The function always terminates with mys(n) = factorial of n
The function always terminates with mys(n) = 1+2+...+n
The function terminates for non-negative n with mys(n) = factorial of n
The function terminates for positive n with mys(n) = factorial of n