Thread: Hollow triangle

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    37

    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?

  2. #2
    Registered User
    Join Date
    Oct 2010
    Posts
    37
    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.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    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 '+'.

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    37
    Thanks a lot, I wasn't seeing it that way before.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursive Triangle Function
    By w2look in forum C Programming
    Replies: 14
    Last Post: 11-13-2010, 02:31 PM
  2. Help making Triangle
    By jensklemp in forum C++ Programming
    Replies: 4
    Last Post: 02-11-2010, 03:59 PM
  3. Clipping a Triangle of Digits
    By towely in forum C++ Programming
    Replies: 3
    Last Post: 10-26-2009, 07:00 AM
  4. Right Triangle Program
    By BSmith4740 in forum C# Programming
    Replies: 9
    Last Post: 02-27-2008, 12:24 AM
  5. Just in case: "Odd" Triangle Challenge (for me)
    By BB18 in forum C Programming
    Replies: 3
    Last Post: 10-09-2004, 12:02 AM