C# christmas tree

后端 未结 1 969
醉梦人生
醉梦人生 2021-01-13 09:18

I\'m novice in C# and cause I request help me to implement this:

        *
        *
       ***
        *
       ***
      *****
        *
       ***
      *****
          


        
相关标签:
1条回答
  • 2021-01-13 09:54
    Console.WriteLine("Please enter the number of triangles in your tree: ");
    int n = int.Parse(Console.ReadLine());
    
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < i; j++)
        {
            string branch = new String('*', j);
            Console.WriteLine(branch.PadLeft(n + 3) + "*" + branch);
        }
    }
    

    A working example.

    0 讨论(0)
提交回复
热议问题