Computer Science, asked by priyarocks04, 9 months ago

Consider the following function f:
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 positive n with mys(n) = factorial of n
The function terminates for positive n with mys(n) = 1+2+...+n

Answers

Answered by DaxayMakwana
21

Answer:

function terminates for positive n with mys(n), so go for option 4

Explanation:

as we have condition to check number is 1 to terminate the recursion, if we give negative number then this condition never arise

Answered by AskewTronics
4

Option "The function terminates for positive n with mys(n) = 1+2+...+n" will give the correct answer.

Explanation:

The above-defined function is written in the python language, which is a recursive function, and when a user passes any positive number, then the all number from 1 to n will be added and the result will be returned. The last option also states the same, Hence it is a true option while the other is not because:-

  • The first option states that the function always returns the factorial of n which is not correct.
  • The second option states that the function gives the addition of all numbers from 1 to n, but that function is returned error for the negative number.
  • Then the second-last option states that the function returned factorial of n which is not correct.

Learn More :

  • Python : https://brainly.in/question/14689905
Similar questions