% factorial_stepping2.m
% Show how to compute a sequence of factorials, using stepping stones,
% and keeping the previous value.
%
nmax = input ( 'Enter NMAX, highest factorial to compute: ' );

for n = 0 : nmax

  if ( n == 0 )
    factold = 0;
    fact = 1;
  else
    factold = fact;
    fact = factold * n;
  end

  fprintf ( ' %d', fact );

end

fprintf ( '\n' );

