Think about it: what is common to all the prints?
1
23
456
789
1
23
456
78910
1
23
456
78910
1112
They all start with the same number, and each successive line has one more number printed, until the target number is done.
So you need a loop, which prints all the number up to and including the target. Write that first, and test it. Make sure it prints exactly what you expect under all circumstances:
123456789
12345678910
123456789101112
When that works, add a variable outside the loop called
printLineAt
and a second called
printingAt
. Set both to 1.
Then inside the loop reduce
printingAt
by one and check it.
If it is zero, increment
printLineAt
and a set
printingAt
to the new value. Then print a newline.
Try it, it's not as complicated as you think.