Factorial Function Code in Matlab

Factorial Function
%First

function y =fact(n)

if n~=0
    y=n*fact(n-1);
else
    y=1;
end

%Second
function y =Factnew(n)
y=prod(1:n);
end

%Third

function y =fact(n)
y=1;
for p=1:n
y=y*p;
end

Comments