Computer Science, asked by sweety1612, 1 year ago

consider the following function def f(m) :if m==0 return (0)else: return (m+f(m-1))​how will the function terminates

Answers

Answered by sreesuryaprakash
3

Answer:

It gives you the sum of the given number m, i.e. Σ(m), where m >= 0

Explanation:

The function is a recursive function with the termination condition that returns 0.

As a result, the output of the function would be, m+m-1+m-2+...1+0 -> Σm.

However, if m < 0, this goes into an infinite recursion, this causing a stack overflow, in most of the computer language runtimes

Similar questions