Simple loop

This is a discussion on Simple loop within the C++ Programming forums, part of the General Programming Boards category; Hello all, i want to display a triangle like this: * * * * * * * * * * ...

  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
    32,824
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 06: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, 05:13 AM

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