function xplusy ( N )

%*****************************************************************************80
%
%% XPLUSY creates a histogram of the sum of N random variables.
%
%  Discussion:
%
%    This m-file produces 5,000 values of the sum of N random
%    variables, each variable uniform from 0 to 1, and independent.
%    It then plots a histogram of the sums using 100 bins.
%
%  Modified:
%
%    28 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
%  Parameters:
%
%    Input, integer N, the number of variables in each sum.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'XPLUSY:\n' );
  fprintf ( 1, '  This m-file produces 5,000 values of the sum of N random\n' );
  fprintf ( 1, '  variables, each variable uniform from 0 to 1, and independent.\n' );
  fprintf ( 1, '  It then plots a histogram of the sums using 100 bins.\n' );

  mean = N / 2;
  sd = sqrt ( N / 12 );
  for sumn = 1 : 5000
    s = 0;
    for i = 1 : N
      s = s + rand ( );
    end
    s = ( s - mean ) / sd;
    z(sumn) = s;
  end
%
%  Graphics.
%
  clf
  hist ( z, 100 )
  grid on
  xlabel('sum')
  ylabel('number of values per bin')
  title('Histogram of the Sum of N Random Variables')
  print ( '-dpng', 'xplusy.png' );

  return
end
