Thread: Simple loop

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    17

    Simple loop

    Hello all, i want to display a triangle like this:

    *
    * *
    * * *
    * * * *
    I thought about it and tried all day but unfortunately didn't do it.
    This is so for i've done.

    Code:
    for(int i=0; i<5; i++)
    {
    for(int j=5; j>i; j--)
     
      for(int k=0; k<i; k++)
        cout<<"*";
        cout<<" ";
    
        cout<<"\n";
    }
    Please let me know where i'm wrong in this loop.

    Thanks in advance..

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. having problem with a simple loop
    By everyone0 in forum C Programming
    Replies: 6
    Last Post: 05-28-2010, 05:22 AM
  2. Trying to figure out a simple loop....
    By chadsxe in forum C++ Programming
    Replies: 9
    Last Post: 01-05-2006, 01:31 PM
  3. simple collision detection problems
    By Mr_Jack in forum Game Programming
    Replies: 0
    Last Post: 03-31-2004, 04:59 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. for loop or while loop
    By slamit93 in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2002, 04:13 AM