function [ p, q ] = i4cf_evaluate ( n, a, b )

%*****************************************************************************80
%
%% i4cf_evaluate() evaluates a continued fraction with I4 entries.
%
%  Discussion:
%
%    For convenience, we omit the parentheses or multiline display.
%
%    CF = A(0) + B(1) / A(1) + B(2) / A(2) + ... A(N-1) + B(N) / A(N).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 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.
%
%  Input:
%
%    integer N, the number of continued fraction
%    coefficients.
%
%    integer A(N+1), B(N+1), the continued fraction 
%    coefficients.  The first entry of B is ignored.
%
%  Output:
%
%    integer P(N+1), Q(N+1), the N+1 successive approximations
%    to the value of the continued fraction.
%
  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) + b(i+1) * 1;
      q(i+1) = a(i+1) * q(i) + b(i+1) * 0;
    else
      p(i+1) = a(i+1) * p(i) + b(i+1) * p(i-1);
      q(i+1) = a(i+1) * q(i) + b(i+1) * q(i-1);
    end

  end

  return
end
