function c = catalan_number ( n )

%*****************************************************************************80
%
%% catalan_number() computes a Catalan number.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 April 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N: the index of the Catalan number.
%
%  Output:
%
%    integer C: the value of the Catalan number.
%
  if ( n < 0 )
    c = 0;
    return;
  end

  c = 1;
%
%  The extra parentheses ensure that the integer division is
%  done AFTER the integer multiplication.
%
  for i = 1 : n
    c = ( c * 2 * ( 2 * i - 1 ) ) / ( i + 1 );
  end

  return
end
