function bc = binomial ( top, bottom )

%*****************************************************************************80
%
%% BINOMIAL computes the binomial coefficient N-choose-K.
%
%  Modified:
%
%    07 May 2019
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
%  Input parameters:
%
%    Input, integer TOP, BOTTOM, the values of N and K.
%
  if ( top == 0 || top == 1 )
    num = 1;
  else
    x = 2 : top;
    num = prod ( x );
  end

  if ( bottom == 0 || bottom == 1 )
    den1 = 1;
  else
    x = 2 : bottom;
    den1 = prod ( x );
  end

  test = top - bottom;
  if ( test == 0 || test == 1  )
    den2 = 1;
  else
    x = 2 : test;
    den2 = prod ( x );
  end

  bc = ( num / den1 ) / den2;

  return
end
   