% pascal_prob.m
%  Plot the entries in row N of Pascal's triangle, divided by 2^n,
%  so the K-th value is the probability of K heads in N tosses.
%
n = input ( 'Enter the row to plot: ' );

value_list = [];

for k = 0 : n

  if ( k == 0 )
    value = 1;
  else
    value = value * ( n + 1 - k ) / k;
  end
%
%  Divide the value by 2^n, so it's a probability now.
%
  value_list = [ value_list, value / 2^n ];

end

bar ( 0:n, value_list );
title ( 'Probabilities of K heads in N tosses' );
xlabel ( '<-- K = number of heads -->' );
ylabel ( '<-- Probability -->' );
