How to print an isosceles triangle

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2011-01-13T02:26:28Z Indexed on 2011/01/13 5:53 UTC
Read the original article Hit count: 220

Filed under:
|
|

Hello,

I'm trying to learn programming by myself, I'm working from a book that has the following problem which I can't solve:

Allow the user to input two values: a character to be used for printing an isosceles triangle and the size of the peak for the triangle. For example, if the user inputs # for the character and 6 for the peak, you should produce the following display:

#

##

###

####

#####

######

#####

####

###

##

#

This is the code I've got so far:

        char character;
        int peak;

        InputValues(out character, out peak);

        for (int row = 1; row < peak * 2; row++)
        {
            for (int col = 1; col <= row; col++)
            {                    
                Console.Write(character);
            }
            Console.WriteLine();
        }
        Console.Read() // hold console open

Thanks in advance.

© Stack Overflow or respective owner

Related posts about c#

Related posts about loops