function r = AddJc(n)n=input('请输入n的值:')%阶乘求和k=1;r=0;while k<=n r = r + Jc(k) k=k+1;end function s=Jc(m) s=1;k=1; while k<=m s=s*k; k=k+1; end
Matlab 自带函数 factorial(4)ans = 24