You’re almost there. You have to set the upper limit of your ‘j’ loop to be the current value of ‘i’:
for i=1:10;
for j=1:i
fprintf( '%5d',j);
end
fprintf('\n');
end;
By the way, it is generally not a good idea to use ‘i’ and ‘j’ as variables, including loop counters. MATLAB uses them for its imaginary operators, and using them as variables can cause confusion in those instances.
Best Answer