马上就到圣诞节啦,这里我写啦一个最简单的圣诞树代码
Console.WriteLine("请输入您需要的圣诞树的大小<数字>");
int n = int.Parse(Console.ReadLine());
int i, j, k, m;
for (i = 1; i <= n / 2; i++)
{
for (j = 1; j < n / 2 + i; j++)
{
if (j <= n / 2 - i)
Console.Write(" ");
else {
if (j % 2 == 0)
Console.Write("$");
else
Console.Write("*");
}
}
Console.WriteLine("\n");
}
for (k = n / 2 + 1; k <= n - n / 4; k++)
{
for (m = 1; m <= n + 1; m++)
{
if (m != n / 2)
Console.Write(" ");
else
Console.Write("||");
}
Console.WriteLine("\n");
}
Console.ReadKey();
输出后结果如图所示: