HOW TO MAKİNG PASCAL TRİANGLE !!!

조회 수: 14 (최근 30일)
Emre Tutucu
Emre Tutucu 2020년 5월 15일
댓글: Emre Tutucu 2020년 5월 15일
how can i do this ?
1
121
12321
1234321
123454321
  댓글 수: 3
Emre Tutucu
Emre Tutucu 2020년 5월 15일
I create the triangle but the number combination is wrong
n=5;
for i=1:n
for j=1:n-i
fprintf(' ');
end
for j=1:i
fprintf(' %d',j);
end
fprintf('\n');
end
1
121
12321
1234321
123454321 have to like that..
Emre Tutucu
Emre Tutucu 2020년 5월 15일
but this is the result I got: 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

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

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 5월 15일
emre - your code needs a third loop to countdown from the middle number to 1. Just add the following code after the second loop so that you print out the missing numbers. Note that you will need to adjust the first for loop so that the spacing is created appropriately.
for j=i-1:-1:1
fprintf(' %d',j);
end
  댓글 수: 1
Emre Tutucu
Emre Tutucu 2020년 5월 15일
thank you so much !
its works...

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by