нарисовать елку c#

помогите пожалуйста это написать, я только начал изучать шарп, не понимаю что не так. вот мой код:

namespace Exercise021
{
  using System;
  public class Program
  {
    public static void Main(String[] args)
      {
            PrintRightTriangle(4);
      }

      public static void PrintStars(int number)
    {
          var star = String.Concat(Enumerable.Repeat("*", number));
          Console.Write(star);
    }

    public static void PrintSpaces(int number)
    {
            var space = String.Concat(Enumerable.Repeat(" ", number));
            Console.Write(space);
    }

    public static void PrintRightTriangle(int size)
        {
            for (int f = 1; f <= size; f++) {
                for (int i = 1; i <= size; i++)
                {
                  PrintStars(i);
                }
                PrintSpaces(f);
                Console.WriteLine("");

            }
        }
   }
}

задача:

Section 1 Define a method called PrintSpaces(int number) that produces the number of spaces specified by number. The method does not print the line break.

You will also have to either copy the PrintStars method from your previous answer or reimplement it in this exercise template.

Section 2 Create a method called PrintRightTriangle(int size) that uses PrintSpaces and PrintStars to print the correct triangle. So the method call PrintRightTriangle(4) should print the following:

// NOTICE THE AMOUNT OF WHITESPACE    
   *  
  **  
 ***  
****

Note! The comments in this and next examples are not part of the print, but only to emphasize the difference to previous work. Section 3 Define a method called ChristmasTree(int height) that prints the correct Christmas tree. The Christmas tree consists of a triangle with the specified height and the base. The base is two stars high and three stars wide, and is placed at the center of the triangle's bottom. The tree is to be constructed by using the methods PrintSpaces and PrintStars.

For example, the call ChristmasTree(4) should work as following:

// NOTICE THE AMOUNT OF WHITESPACE
   * 
  *** 
 *****
******* 
  *** 
  ***

The call ChristmasTree(10) should work like this:

// NOTICE THE AMOUNT OF WHITESPACE
         * 
        *** 
       ***** 
      ******* 
     ********* 
    *********** 
   ************* 
  *************** 
 ***************** 
******************* 
        *** 
        ***

Note! Heights shorter that 3 don't have to work correctly!


Ответы (2 шт):

Автор решения: Eugene X

На Си ёлка выглядит примерно вот так...

Где repn - вывести в консоль символ ch, c раз.

А nl - вывести знак новой строки.

#include <stdio.h>
#include <stdlib.h>

void repn(int c, char ch) {
    char *cc = (char*) calloc(c+1, 1);
    memset(cc, ch, c);
    fputs(cc, stdout);
    free(cc);
}

void nl() {
    fputs("\n", stdout);
}

int main() {
    int sp = 8,
        eg = 1;
    while (sp > 1) {
        repn(sp, ' ');
        repn(eg, '#');
        nl();
        sp -= 1;
        eg += 2;
    }
    repn(7, ' '); repn(3, '#'); nl();
    repn(7, ' '); repn(3, '#'); nl();
}
→ Ссылка
Автор решения: aepot

Всё намного проще, чем кажется, простая математика. Даже проще, чем в условии написано.

static void PrintSpaces(int number)
{
    string spaces = new string(' ', number);
    Console.Write(spaces);
}

static void PrintStars(int number)
{
    string stars = new string('*', number);
    Console.WriteLine(stars);
}

static void ChristmasTree(int height)
{
    for (int i = 0; i < height; i++)
    {
        int offset = height - i - 1;
        PrintSpaces(offset);
        int width = i * 2 + 1;
        PrintStars(width);
    }
    
    for (int i = 0; i < 2; i++)
    {
        PrintSpaces(height - 2);
        PrintStars(3);
    }
}
→ Ссылка