How to draw an euqilateral triangle.

This is a discussion on How to draw an euqilateral triangle. within the C Programming forums, part of the General Programming Boards category; Hey, I've been at this for a few days now and I cannot for the life of me figure this ...

  1. #1
    Unregistered
    Guest

    Angry How to draw an euqilateral triangle.

    Hey, I've been at this for a few days now and I cannot for the life of me figure this one out.
    I need to draw a trinagle with "*" and "-" that looks like this

    *--------
    **-------
    ***------
    ****-----
    *****----
    ****-----
    ***------
    **-------
    *--------
    it doesn't look like it in the picture but the picture is supposed to be a complete square with and odd number of rows and columns.
    I am at my wit's end on this. I don't even know how to begin on this. In the rest of my program I have already used FOR loops to draw other types of triangles, but this one is just killing me. Thank you for any help. It is greatly appreciated.

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523

    triangle

    this may be a messy way but I'ts the best I can do at this time of night

    Code:
    #include <stdio.h>
    
    int main()
    {
    	int star, dash, x;
    	
    	star = 1;
    	dash = 8;
    
    	while(star<6)
    	{
    		for(x = 0; x < star; x++)
    			putchar('*');
    		for(x = 0; x < dash; x++)
    			putchar('-');
    
    		putchar('\n');
    		star++;
    		dash--;
    	}
    
    	star = 4;
    	dash = 5;
    
    	while(star>0)
    	{
    		for(x = 0; x < star; x++)
    			putchar('*');
    		for(x = 0; x < dash; x++)
    			putchar('-');
    
    		putchar('\n');
    		star--;
    		dash++;
    	}
    	return 0;
    }
    You can probably improve this, I'll leave that up to you as you should do some homework
    All spelling mistakes, syntatical errors and stupid comments are intentional.

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. Right Triangle Program
    By BSmith4740 in forum C# Programming
    Replies: 9
    Last Post: 02-26-2008, 11:24 PM
  3. Which is the better way to draw?
    By g4j31a5 in forum Game Programming
    Replies: 16
    Last Post: 01-22-2007, 10:56 PM
  4. Draw a triangle
    By Hikaru in forum C++ Programming
    Replies: 8
    Last Post: 08-13-2006, 02:26 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