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

%*****************************************************************************80
%
%% R8SCF_EVALUATE evaluates a simple continued fraction with R8 entries.
%
%  Discussion:
%
%    The simple continued fraction with real coefficients is:
%
%      SCF = A(0) + 1 / ( A(1) + 1 / ( A(2) ... + 1 / A(N) ) )
%
%    This routine returns the N 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 C(N)/D(N).
%
%  Licensing:
%
%    I don't care what you do with this code.
%
%  Modified:
%
%    03 August 2017
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the number of continued fraction
%    coefficients.
%
%    Input, real A(1:N+1), the continued fraction coefficients.
%
%    Output, real P(1:N+1), Q(1:N+1), 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
