这个Scilab函数应该计算n的阶乘。但它给出了下面所述的错误:
function fac(n)
if (n<=0) then n = 1
else
n = n* fac(n-1)
end
endfunction
错误在此处说明:
-->fac(23)
!--error 44
Wrong argument #2.
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
at line 5 of function fac called by :
fac(23)
答案 0 :(得分:1)
你在n =
之后的第一行忘记了返回值function
,否则它将永远不会返回任何内容
function n = fac(n)
if (n<=0) then n = 1
else
n = n* fac(n-1)
end
endfunction