function e_spigot ( n )

%*****************************************************************************80
%
%% e_spigot implements the "e spigot" algorithm for decimal digits of e.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    25 February 2019
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Stanley Rabinowitz, Stan Wagon,
%    A spigot algorithm for the digits of pi,
%    American Mathematical Monthly,
%    Volume 102, Number 3, pages 195-203, March 1995.
%
%  Input:
%
%    integer N, the number of digits to compute.
%
  a = ones ( n + 1, 1 );

  fprintf ( 1, '2.' );
  for j = 1 : n - 1
    a = a * 10;
    q = 0;
    for i = n : -1 : 1
      a(i) = a(i) + q;
      q = floor ( a(i) / ( i + 1 ) );
      a(i) = mod ( a(i), i + 1 );
    end
    fprintf ( 1, '%d', q );
  end
  fprintf ( 1, '\n' );

  return
end

