% Problem 2 of HW 14
clear
n = input('Input n: ');
heads = 0;
tails = 0;
for i = 1:n
flip = rand;
if(flip > 0.5)
tails = tails + 1;
else
heads = heads + 1;
end
end
heads = heads/n
tails = tails/n
% For n = 500, there can be quite a difference between the observed percentages
% and the expected percentages and large variation in this differnce. This gets a
% little better when n = 10000 and much better when n = 1000000.