how can someone make a 1234,123,12,1 pattern in a triangle

4 views (last 30 days)
when n=1,how can I do a pattern from 1:n so it printed out like that(using for or while loop)
123456
12345
1234
123
12
1
  3 Comments
John D'Errico
John D'Errico on 23 Dec 2015
Please stop asking the same question repeatedly. Asking the same question over and over again will not get you a better answer.

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 23 Dec 2015
Edited: James Tursa on 23 Dec 2015
Here is a start for you. It might be easier to construct the loop using backwards indexing. E.g.,
n = 6;
for k=n:-1:1
% Insert code here for your number
end
So you need to fill in the loop above. E.g., when k=6 at the first iteration, how do you form the number 123456? Then when k=5 in the next iteration, how do you form the number 12345? Etc. Maybe you can think of a vectorized way to do this, or maybe you can think of another loop to do this. If you are stuck with how to code this, try to think of how you might do it by hand first. Then come up with a pattern that you can code up.

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!