#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    12
    Rep Power
    0

    Cool how to print a triangle by using while loop in c??


    Write a program that uses one or more while statements to create the following output:

    @

    @@

    @@@

    @@@@

    @@@@@

    @@@@@@
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    325
    Rep Power
    12
    Code:
    int main()
    {
        draw_triangle(5);
    }
    
    void draw_triangle(int size)
    {
      
       for (int i=0; i<size; i++)
       {
           for (int j=0; j<i; j++)  printf("*");
           printf("\n");
        }
    }
  4. #3
  5. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    lazy_yogi, you shouldn't do homework for these guys! At least they could search through the archives and get the solution from the 50 other times one was posted.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  6. #4
  7. No Profile Picture
    Can this change?
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    266
    Rep Power
    11
    Freaking argh!

    hkboy, I suggest you put forth some effort in your studies. You'll get NOWHERE going to other people for solutions. We're here to help you along, NOT solve your homework problems.*

    *Well. . .most of us aren't here to do your homework. :rolleyes:
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    325
    Rep Power
    12
    mitakeet: Yeh you're right. didn't think of that.

    tho having said that, it can be hard to do the very basics for a new programmer who has no past domain specific knowledge to draw on.

    But yea, I should have left it for him to alteast try start on before helping

IMN logo majestic logo threadwatch logo seochat tools logo