Write a MATLAB function named getfact that accepts a nonnega
Solution
The function get_fact returns the factorial n! of a non-negative number
function get_fact(n)
if n<0
error(\'error\')
end
if n>=0
fact=1;
for i=1:n-1
i=i+1
fact=fact*i
end
end
______________________________________________________________________________________________________________________________________________________________________
if n<0 returns a error message. at the Matlab workspace
get_fact(-1)
??? Error using ==> get_fact at 3
error
__________________________________________________________________
At the Matlab workspace, If you try to find 4! then you should write the following
line (at the Matlab workspace)
get_fact(4)
fact =
2
fact =
6
fact =
24
____________________________________________________________________________
n=10!
get_fact(10)
fact =
2
fact =
6
fact =
24
fact =
120
fact =
720
fact =
5040
fact =
40320
fact =
362880
fact =
3628800
__________________________________________________________________

