+ 3

Consider the following function fdef f(m): if m == 0: return(1) else: return(m*f(m-1))

Which of the following is correct? 1)  The function always terminates with f(n) = n  2) The function always terminates with f(n) = factorial of n  3) The function terminates for non-negative n with f(n) = n  4) The function terminates for non-negative n with f(n) = factorial of n

16th Feb 2018, 3:21 AM
I Am a Baked Potato
I Am a Baked Potato - avatar
7 Answers
+ 4
The trap is the infinite loop for negatives. so the "always" answers are wrong. since it is recursion 3) is wrong 4 is correct
16th Feb 2018, 6:02 AM
Oma Falk
Oma Falk - avatar
+ 2
Thanks for suggestion...but it's a place where i can find answer for some of the question..
16th Feb 2018, 3:32 AM
I Am a Baked Potato
I Am a Baked Potato - avatar
+ 1
Hey Tushar! This section is the Q&A section, meaning if you have a question about coding, this is where it should be asked. It seems that you may just be posting quizzes, but you can make your own in the quiz factory so you should probably avoid doing so here. Of course, if you are genuanly curious about the answer to the questions, you should try wording it in a way that actually asks people to help you out with it or that you may not understand a certain part, as opposed to just telling them to solve it. Thanks!
16th Feb 2018, 3:30 AM
Faisal
Faisal - avatar
+ 1
Also the answer is 4 ;)
16th Feb 2018, 3:31 AM
Faisal
Faisal - avatar
0
I think function always terminate with return 1 whatever number you choose. So , i think answer 4 non-negative may be.
16th Feb 2018, 3:33 AM
Sylar
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 please tell me the answer
22nd Aug 2018, 6:01 AM
arpita halder
arpita halder - avatar
0
3rd option
30th Jul 2019, 5:07 AM
Anuj Kumar