Drawing this shape using *

2 views (last 30 days)
Kenan Baira
Kenan Baira on 23 Feb 2019
Commented: Star Strider on 24 Feb 2019
How to draw This Shape
*
* *
* *
* *
* *
I tried to play around some nested loops and didn't work for me

Accepted Answer

Star Strider
Star Strider on 23 Feb 2019
This takes me back to my FORTRAN days in the late 1960s when line printer code similar to this was the only option for plotting.
Try this:
spc = uint16(' ');
ast = uint16('*');
tringl = char(ones(6,6,'uint8')*32);
for k1 = 2:size(tringl,1)
tringl(k1,[8-k1,4+k1]) = ast;
end
for k1 = 1:size(tringl,1)
fprintf(1, '%s\n', tringl(k1,:))
end
Experiment to get the result you want.
  7 Comments
Walter Roberson
Walter Roberson on 24 Feb 2019
What is your current code?
Star Strider
Star Strider on 24 Feb 2019
My pleasure.
Index the character array to fill stars from the centre to each side, incrementing by 1 in each iteration.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!