settingsAccountsettings
Menusettings

Q: How to create a Christmas Tree in C#?

+2 votes

I need to create a Christmas Tree (pinetree) for my project in C#.... by using 10 stars

It must be 10 * high (*<-- this is a strar :-)

Must look like this:

Christmas Tree in C#

Can you please help me! Thanks!

asked in C# category by user Jolie Ann
edited by user golearnweb

1 Answer

+2 votes
 
Best answer

Here's one - just copy-paste it in your Visual Studio or whatever IDE you are using to see it in colors:

using System;

class ChristmasTree
{
    static void Main()
    {
        int spaces = 10;
        int asterix = 1;
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < spaces; j++)
            {
                Console.Write(" ");   
            }
            for (int j = 0; j < asterix; j++)
            {
                Console.Write("* ");
            }
            Console.WriteLine();
            asterix++;
            spaces--;
        }
    }
}

 

answered by user richard8502
edited by user golearnweb
Thanks! It worked!
...