% hw024.m
% John Burkardt
% Probability that random x, y and z can be the sides of a triangle.
%
n = input ( 'Enter number of trials: ' );

m = 0;

for i = 1 : n

  x = rand ( );
  y = rand ( );
  z = rand ( );

  if ( ...
    ( z <= x + y ) && ...
    ( y <= x + z ) && ...
    ( x <= y + z ) )
    m = m + 1;
  end

end

fprintf ( '  Using %d trials, estimated probability is %g\n', n, m / n );
