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 Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by