function cointosses(n,p)

% cointosses(n,p) simulates tossing a coin n times, with probability p of heads

A = 0;
heads = 0;

for i=1:n
    if rand<=p 
    A = [A,'H'];
    heads = heads+1;
    else A = [A,'T'];
    end
end
disp(['The result of tossing a coin ', num2str(n) ' times is ', num2str(A(1,2:n+1))])
disp(['The proportion of heads is ', num2str(heads/n)])

 

 