clear n = 100000; k = 0; for i = 1:n; x = rand(1); y = rand(1); z = (x^2 + y^2)^.5; if z <= 1; k = k + 1; end end pi = 4*k/n