C # christmas tree

I am new to C # and call that I am asking to help me implement this:

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

I only have this code:

class Program { static void Main(string[] args) { AnotherTriangle ob = new AnotherTriangle(); ob.CreateTriangle(); Console.ReadLine(); } } class AnotherTriangle { int n; string result = "*"; public void CreateTriangle() { flag1: Console.Write("Please enter number of triangles of your tree: "); n = int.Parse(Console.ReadLine()); Console.WriteLine(); if (n <= 0) { Console.WriteLine("Wrong data type\n"); goto flag1; } string s = "*".PadLeft(n); for (int i = 0; i < n; i++) { Console.WriteLine(s); s = s.Substring(1) + "**"; for (int j = 0; j < n; j++) { Console.WriteLine(s); } } } } 

Currently, I only have a "tower", not an equilateral triangle. Please, help.

+5
source share
1 answer
 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); } } 

Working example.

+9
source

Source: https://habr.com/ru/post/1232524/


All Articles