Use the formulas s1 1 and sn sn1 middot for n greaterthano

Use the formulas s_1 = 1 and s_n = s_n-1 middot for n greaterthanorequalto 2 to write a recursive algorithm that computes s_n = n! You may use any style of pseudo-code to write your algorithm, but make sure that the steps of your algorithm are clear.

Solution

function s = recursive_sum(n) s=0; for i=1:length(n) if isnumeric(n{i}) s = s + n{i}; else s = s + recursive_sum(n{i}); end end end
 Use the formulas s_1 = 1 and s_n = s_n-1 middot for n greaterthanorequalto 2 to write a recursive algorithm that computes s_n = n! You may use any style of pse

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site