% Pascal's Triangle

r = input('Rows? ');

% Initially a row with open 1 locked in and 0's
x = zeros(1,r+1);
x(1) = 1;

% Loop for each row of Pascal's Triangle, assume 5 rows
for ii = 1:r

      % Display decreasing numbers of spaces to get indenting
      fprintf('%s', blanks((r+1)*2-ii*2));

      % Display only the non-zero values of the array
      % One more value each row is printed to form triangle
      fprintf('%4d', x(1:ii));

      % End of the row, close with carriage return
      fprintf('\n')

      % Power of Matlab!  Add adjacent columns simultaneously
      x(2:r+1) = x(2:r+1) + x(1:r);
end
 
