-
Hollow triangle
Hi guys, I'm trying to create a program that can print a hollow triangle such as
*
* *
*****
and
*
* *
* *
*******
I know there needs to be nested loops, the part I'm having trouble with is the code which will actually produce the pattern of asterisks and spaces. Anyone have any ideas?
-
Sorry those were supposed to be equalateral triangles with a base of rows*2-1 and asterisks on the line above one column in on each side of the predeceding row. with the rest of it hollow.
-
Code:
++++*
+++*+*
++*+++*
+*+++++*
*********
Take a look at this example where '+' represents a space.
See how each row has one less '+' than the one before it. Then there's the asterisk. Then more '+' for the inside, numbering 1,3,5.
You need to find a pattern there. The outer loop would represent the row number. Then the inner loop would generate the appropriate number of '+'.
-
Thanks a lot, I wasn't seeing it that way before.