crazy triangles

This is a discussion on crazy triangles within the C Programming forums, part of the General Programming Boards category; Code: *** *** *** ** ** ** * * * -sigh- My head's aching, but I can't seem to figure ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    6

    crazy triangles

    Code:
    *** *** ***
    **  **  **
    *   *   *
    -sigh- My head's aching, but I can't seem to figure out how to generate that figure using the for loop and putchar('*').
    Any help would be greatly appreciated.
    Last edited by markg; 10-24-2005 at 10:36 AM. Reason: figure won't show correctly

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    no need to start a new thread, especially since nobody will know what you are talking about if they don't read the other one. Again, like I said, just read an intro to C++ to understand what a for loop is, if you can't do that, then just give up and become an accountant.

  3. #3
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Simple!
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        int i;
        for (i = 0; i < 1; i++) /* required for loop */
        {
            putchar('*'); putchar('*'); putchar ('*');
            putchar(' ');
            putchar('*'); putchar('*'); putchar ('*');
            putchar(' ');
            putchar('*'); putchar('*'); putchar ('*');
            putchar(' ');
            putchar('\n');
            putchar('*'); putchar('*');
            putchar(' '); putchar(' ');
            putchar('*'); putchar('*');
            putchar(' '); putchar(' ');
            putchar('*'); putchar('*');
            putchar(' '); putchar(' ');
            putchar('\n');
            putchar('*');
            putchar(' '); putchar(' '); putchar(' ');
            putchar('*');
            putchar(' '); putchar(' '); putchar(' ');
            putchar('*');
            putchar(' '); putchar(' '); putchar(' ');
            putchar('\n');
        }
        return 0;
    }
    Moral of this story, read the sticky concerning homework threads and make an attempt first.

    Can you even work out the program in some form of pseudocode? Obviously, loops will be involved, what are the starting and ending values, etc.?

  4. #4
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    yea that will do! and it uses a for loop!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-08-2009, 11:13 AM
  2. Scroll Bars Are Scrolling Me Crazy
    By Iyouboushi in forum C# Programming
    Replies: 6
    Last Post: 03-03-2006, 01:43 PM
  3. going crazy over copy
    By strij85 in forum C++ Programming
    Replies: 10
    Last Post: 07-23-2004, 12:38 AM
  4. crazy
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 08-31-2002, 09:54 PM
  5. crazy output
    By asirep in forum C Programming
    Replies: 22
    Last Post: 04-09-2002, 12:41 PM

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