Need help getting this output for C++ lang

hi i need help on getting this kind of output, badly needed to finish this cuz I've been scrambling my brain to think of a looping that to generate this kind of output...thanks in advance

1
2
3
4
5
6
7
8
9
10
        1=9
       12=98
      123=987
     1234=9876
    12345=98765
   123456=987654
  1234567=9876543
 12345678=98765432
123456789=987654321
The most important thing to notice is the patterns of 3 different things:
1. The spaces on the left
2. The highest number on the left
3. The lowest number on the right
Each of these 3 things can be represented by some type of loop that increments or decrements a counter variable (such as a for loop)
1
2
3
4
5
6
7
8
9
        1=9
       12=98
      123=987
     1234=9876
    12345=98765
   123456=987654
  1234567=9876543
 12345678=98765432
123456789=987654321
8 spaces | 1 | 9
7 spaces | 2 | 8
6 spaces | 3 | 7
5 spaces | 4 | 6
4 spaces | 5 | 5
3 spaces | 6 | 4
2 spaces | 7 | 3
1 space  | 8 | 2
0 spaces | 9 | 1

If I take a step back and think about a loop to control all 3 instead of individual loops, I notice that 9-<first column> = <second column> and 1+<first column> = <third column>
So if there was a loop that kept track of the <first column>, I would also know the starting numbers for the <second column> and <third column> loops by applying those formulas

1
2
3
4
5
for(int i=8; i>=0; i--) {
    //increasing for loop to print i spaces
    //increasing for loop to print digits from 1 to 9-<first column> aka 9-i
    //decreasing for loop to print digits from 9 to 1+<first column> aka 1+i
}


You could also base the control loop off of either of the other 2 columns, but I will leave that as an exercise for the reader.
super thanks "kevinkjt2000" you've helped me a lot. now I'm laughing on my stupidity now hahaha...lol all that i need is the logic for the spacing now my looping is now working. And now my mind will be at ease hahahahah...on to my next exercise....
Topic archived. No new replies allowed.