圣诞节即将来临在这里使用特殊的方式提前祝我的粉丝朋友们圣诞快乐~~
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入你需要的圣诞树层数(2~4)之间");
int a = Convert.ToInt32(Console.ReadLine());
int wth = 2 * (3 + a);
for (int k = 3; k < 3+a; k++)
{
Trees(k,wth);
}
TreesBranch(wth);
}
//圣诞树函数
static void Trees(int high ,int width)
{
for (int i = 0; i < high; i++)
{
for (int j = 0; j < width; j++)
{
if (j >= (width/2 - i) && j <= (width/2 + i))
{
Console.Write("*");
}
else Console.Write(" ");
}
Console.WriteLine();
}
}
//圣诞树树干
static void TreesBranch(int width)
{
for (int k = 0; k < 6; k++)
{
for (int l = 0; l < width; l++)
{
if (l >= (width / 2 - 1) && l <= (width / 2 + 1))
{
Console.Write("*");
}
else Console.Write(" ");
}
Console.WriteLine();
}
}
}