Consider the following function function calculate( n ) { if(n equals 5) return 5 else return (n + calculate(n-5)) end } Shishir calls the function by the statement, calculate(20). What value will the function return?
Answers
Answered by
0
Answer:
The answer is f(20) = 35.
Explanation:
i) If we translate the code into mathematical expression, the function will be:
f(n) = 5, n = 5;
f(n) = n + (n-5), n ≠ 5
ii) For n = 20,
f(n) = n + (n-5)
Substituting n = 20,
f(20) = 20 + 20 - 5 = 35
iii) Hence, the answer is f(20) = 35.
#SPJ3
Similar questions