The first line has 16 spaces and the number 1, the second line has 14 spaces and 1 2, etc. I'm supposed to use nested for loops. I'm really struggling with this. Thanks for your help!
Thanks! I don't understand how to make it display the correct number of spaces. I understand how to display spaces, of course, but nothing I've tried has turned out right.
Well, to start, you should probably have the first for loop iterate through all the lines. Inside that for loop, you would need to find out the number of spaces required based on the current line. Once you find that number, you can use a for loop to print all of the spaces. Then you just add another for loop to print all the numbers.
Well, the pattern 1=16, 2=14, 3=12, ... looks like f(m) = 18 - 2m = 2(9 - m) to me, so you could stick to a normal incrementing loop (1, 2, 3, ...) and then calc how much padding you need to add with the inner loop from that.
And the inner loop shouldn't be outputting 1..9 each time, should it!
If only there was some way to only output "1" in the first loops, and then "1 2" in the second loop, and then "1 2 3" in the third loop. The patterm would be something like this:
Hey look! On loop 1 you stop at 1, and on loop 2 you stop at 2, and on loop 3 you stop at 3, and so on. Seems like there a pattern there...
Or here's another way to look at it. Each time, you have to output this much stuff:
1
That's a whole bunch of spaces, and the rest in numbers. Perhaps if you kept track of how many spaces you'd written, you'd be able to know how many numbers you had to write.
Welcome to programming, by the way :) This is programming. The art and craft of thinking about problems in such a way that you can apply the solutions in a programming language. The language itself is just syntax. Programming is thinking.