Hollow triangle

This is a discussion on Hollow triangle within the C Programming forums, part of the General Programming Boards category; Hi guys, I'm trying to create a program that can print a hollow triangle such as * * * ***** ...

  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,832
    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, 01:31 PM
  2. Help making Triangle
    By jensklemp in forum C++ Programming
    Replies: 4
    Last Post: 02-11-2010, 02: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-26-2008, 11:24 PM
  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21