Drawing this shape using *

조회 수: 2 (최근 30일)
Kenan Baira
Kenan Baira 2019년 2월 23일
댓글: Star Strider 2019년 2월 24일
How to draw This Shape
*
* *
* *
* *
* *
I tried to play around some nested loops and didn't work for me

채택된 답변

Star Strider
Star Strider 2019년 2월 23일
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
Walter Roberson
Walter Roberson 2019년 2월 24일
What is your current code?
Star Strider
Star Strider 2019년 2월 24일
My pleasure.
Index the character array to fill stars from the centre to each side, incrementing by 1 in each iteration.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by