function y = fact(n)
%This function calculates the factorial of n 
% function y = fact(n)
% input:  n 
% output:  y = the factorial of n (n!)

% internal variable k = loop variable
% initialize accumulation variable
y = 1;
%  use for loop to accumulate the 
% factorial product in the variable y
for k = 1 : n
    y = y * k;
end