MATLAB Answers

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

24 views (last 30 days)
Emre Tutucu
Emre Tutucu on 15 May 2020
Commented: Emre Tutucu on 15 May 2020
how can i do this ?
1
121
12321
1234321
123454321

  3 Comments

Geoff Hayes
Geoff Hayes on 15 May 2020
Emre - this seems like homework, so what have you tried so far? Please show some or all of your work, and discuss any problems and/or errors that you have encountered.
Emre Tutucu
Emre Tutucu on 15 May 2020
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 on 15 May 2020
but this is the result I got: 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 15 May 2020
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 Comment

Emre Tutucu
Emre Tutucu on 15 May 2020
thank you so much !
its works...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!