clc
clear

n = input('Enter the number of points you want to spread in the square: \n');
m = 0;
X = [0:0.01:1];
Y = sqrt(1-X.^2);
plot(X,Y)
hold on

for i=1:n
    x = rand;
    y = rand;
    
    if x^2 + y^2 <= 1
        m = m + 1;
        plot(x,y,'r.')
        hold on
    else
        plot(x,y,'b.')
        hold on
    end
end
pii = m / n * 4
err = abs(pi - pii)/pi *100