I am trying to make a program that will print out 21 rows of x's in the shape of 1 big X. At the 11th row, there will only be one x printed, because I am using that as the middle of the X. I would have no problem with this usually, but the class I am in is requiring that I use loops to make this program. I believe I would use 3 while loops, one to print out the first 10 rows (in each row the x's getting closer together), one to indicate that there will only be one x in the 11th row, and one to make the last 10 rows print out(each time getting further away from each other. My question is- How do I make the spacing of the x's change inside the loops? I don't know how I would write a loop that adds, or takes away, a certain amount of spaces.
Asked
Active
Viewed 157 times
1 Answers
0
If it's always going to be 21 rows of x's with 11th being the converging point, I would first draw it out and try to found the pattern for spaces.
x x //(19 spaces)
x x //(17 spaces)
x x //(15 spaces)
x x // ...
x x
x x
x x
x x
x x
x x
x
x x
...
You can do the same for the leading spaces as well and once you find the pattern, try to use the index (either for loop or while loop) to add (for leading spaces) or subtract (for spaces in between x's) from a certain number.

halfer
- 19,824
- 17
- 99
- 186

sparkhee93
- 1,381
- 3
- 21
- 30