function factorial_recursive_test ( )

%*****************************************************************************80
%
%% factorial_recursive_test tests factorial_recursive().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    21 June 2020
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'factorial_recursive_test:\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  factorial_recursive() evaluates a factorial recursively.\n' );
  fprintf ( 1, '\n' );
  for i = 1 : 10
    k = factorial_recursive ( i );
    fprintf ( 1, '  %d! = %d\n', i, k );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, 'factorial_recursive_test:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );


  return
end
function value = factorial_recursive ( n )

%*****************************************************************************80
%
%% factorial_recursive demonstrates the use of recursion in MATLAB.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 January 2011
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the argument.
%
%  Output:
%
%    integer VALUE, the factorial of N.
%

%
%  Some condition must be checked that allows you to halt the
%  recursion.
%
  if ( n <= 1 )
    value = 1;
%
%  If the condition is not met, you call again, in a way that
%  makes the stopping condition more likely.
%
  else
    value = n * factorial_recursive ( n - 1 );
  end

  return
end
