控制台输出三角形和菱形图案
程序员文章站
2022-06-11 20:43:38
...
int numb = int.Parse(Console.ReadLine());
for (int i = 0; i < numb; i++)
{
for (int j = 0; j < numb-1-i; j++)
{
Console.Write(" ");
}
for (int x = 0; x < i+1; x++)
{
Console.Write("*");
Console.Write(" ");
}
Console.WriteLine();
}
for (int i = 0; i < numb; i++)
{
for (int j = 0; j < numb - 1 - i; j++)
{
Console.Write(" ");
}
for (int x = 0; x < 2*i + 1; x++)
{
Console.Write("*");
}
Console.WriteLine();
}
for (int i = numb-1; i >= 0; i--)
{
for (int j = 0; j <= numb-i-1; j++)
{
Console.Write(" ");
}
for (int x = 0; x < 2 * i - 1; x++)
{
Console.Write("*");
}
Console.WriteLine();
}