% triangular_keep1.m
%  Compute and print the elements of the triangular sequence.
%  0, 1, 3, 6, 10, 15, 21, ...
%  A(0) = 0, A(N) = A(N-1) + N.
%  Do this by keeping one previous value.
%
n = input ( 'Enter the highest index to compute: ' );

for i = 0 : n

  if ( i == 0 )
    a = 0;
  else
    aold = a;
    a = aold + i;
  end

  fprintf ( 'a(%d) = %d\n', i, a );
end

