function [ p, q ] = i4scf_evaluate ( n, a )

%*****************************************************************************80
%
%% I4SCF_EVALUATE evaluates a simple continued fraction with I4 entries.
%
%  Discussion:
%
%    The simple continued fraction with integer coefficients is:
%
%      SCF = A(0) + 1 / ( A(1) + 1 / ( A(2) ... + 1 / A(N) ) )
%
%    This routine returns the successive approximants P(I)/Q(I)
%    to the value of the rational number represented by the continued
%    fraction, with the value exactly equal to the final ratio P(N)/Q(N).
%
%  Licensing:
%
%    I don't care what you do with this code.
%
%  Modified:
%
%    04 August 2017
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    John Hart, Ward Cheney, Charles Lawson, Hans Maehly, Charles Mesztenyi,
%    John Rice, Henry Thatcher, Christoph Witzgall,
%    Computer Approximations,
%    Wiley, 1968.
%
%  Parameters:
%
%    Input, integer N, the number of continued fraction
%    coefficients.
%
%    Input, integer A(0:N), the continued fraction coefficients.
%
%    Output, integer P(0:N), Q(0:N), the numerators and
%    denominators of the successive approximations.
%
  p = zeros ( 1, n + 1 );
  q = zeros ( 1, n + 1 );

  for i = 0 : n

    if ( i == 0 )
      p(i+1) = a(i+1) * 1 + 0;
      q(i+1) = a(i+1) * 0 + 1;
    elseif ( i == 1 )
      p(i+1) = a(i+1) * p(i) + 1;
      q(i+1) = a(i+1) * q(i) + 0;
    else
      p(i+1) = a(i+1) * p(i) + p(i-1);
      q(i+1) = a(i+1) * q(i) + q(i-1);
    end

  end

  return
end
