function p = myfactorial(n); % compute factorial of n = 1 * 2 * ... (n-2)*(n-1)*n p = 1; % variable to store partial products % each step through the loop does one more multiplication % in the sequence of products 1, 1*2, 1*2*3, etc. for i=1:n p = p * i; end end