[Solved] How to create a Christmas Tree in C#?

  

2
Topic starter

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!

1 Answer
2

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--;
        }
    }
}
Share: