% Berechnung der Fakultaet einer natuerlichen Zahl

% if (n<0)
%     return;
% elseif (n==0)
%     fac = 1;
% else
%     fac = 1;
%     for k= 1:n
%         fac = fac * k;
%     end
% end

%%%%%%%%%%%%%%% oder %%%%%%%%%%%%%%%%

% if (n<0)
%     return;
% elseif (n==0)
%     fac = 1;
% else
%     fac = 1;
%     for k=n:-1:1
%         fac = fac * k;
%     end
% end

%%%%%%%%%%%%%%% oder %%%%%%%%%%%%%%%%

if (n<0)
    return;
elseif (n==0)
    fac = 1;
else
    fac = 1;
    k = 1;
    while (k <= n)
        fac = fac * k;
        k = k + 1;
    end
end

fac