TASK: Print a pyramid of stars.
COMMENT:
Problem 3: Print out a pyramid of stars of height 5.
Pyramid of height 5 row blanks *
* 1 4 1
*** 2 3 3
***** 3 2 5
******* 4 1 7
********* 5 0 9
INSTRUCTIONS:
Create an outer loop using "i" as the index, going from
1 to 5.
Create an inner loop, using "j" as the index, to print
the blanks. When i is 1, we need to print 4 stars, then
when i is 2, we need to print 3 stars, and so on. This
suggests that for each value of i, we need to print 5-i stars.
So your "blanks" loop should run from 1 to 5-i.
To print a blank, use this statement:
fprintf ( ' ' );
end your inner loop
Create another inner loop, using "k" as your index,
to print the stars. When i is 1, we print 1 star,
when i is 2, we print 3, and so on. So it seems like
for a given value of i, k should go from 1 to 2*i-1.
fprintf ( '*' )
end your inner loop.
fprintf ( '\n' ); <-- End of this line of the picture.
End the outer loop.
SUBMIT: Your work should be stored in a script file called "hw015.m". Your script file should begin with at least three comment lines:
% hw015.m
% YOUR NAME
% This script (describe what it does)
% Add any comments here that you care to make.
If this problem is part of an assignment, then submit it to Canvas.