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

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 comentarios

This sounds like homework. Are you supposed to use loops, or are you allowed to use vectorized methods?
using vectorized methods not allowed
Please stop asking the same question repeatedly. Asking the same question over and over again will not get you a better answer.

Iniciar sesión para comentar.

 Respuesta aceptada

James Tursa
James Tursa el 23 de Dic. de 2015
Editada: James Tursa el 23 de Dic. de 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.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 23 de Dic. de 2015

Comentada:

el 23 de Dic. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by