% Pascal's Triangle

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

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

      % ----------------------------------------------
      % Display decreasing numbers of spaces to get indenting
      for jj = 1:12-2*ii
          fprintf(' ')
      end

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

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

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