coding a triangle

This is a discussion on coding a triangle within the C++ Programming forums, part of the General Programming Boards category; I was wondering if anyone could help me code a triangle that generates the following output: 1 1 2 3 ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    2

    Exclamation coding a triangle

    I was wondering if anyone could help me code a triangle that generates the following output:

    1
    1 2 3
    1 2 3 4 5
    1 2 3 4 5 6 7
    1 2 3 4 5 6 7 8 9

  2. #2
    Frustrated Programmer :( phantom's Avatar
    Join Date
    Sep 2001
    Posts
    163
    try

    int max; //Max is the highest number you wish to goto

    for (int i =1; i <= max; i++)
    {
    for(int j = 0; j <= i; j++)
    {
    cout<<j<<" ";
    }
    cout<<endl;
    }

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. Resizing a triangle. Why is my code not working?
    By gozu in forum Windows Programming
    Replies: 2
    Last Post: 01-20-2007, 05:40 PM
  4. Just in case: "Odd" Triangle Challenge (for me)
    By BB18 in forum C Programming
    Replies: 3
    Last Post: 10-09-2004, 12:02 AM
  5. Determining a Triangle using get and pointer
    By naynay in forum C Programming
    Replies: 7
    Last Post: 04-11-2003, 05:55 AM

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