怎么用c#编程图中下面那几个星号那样的图形? 10
2个回答
展开全部
Console.WriteLine("ShowLeftARightTriangle:\n");
ShowLeftARightTriangle(3);
Console.WriteLine("\nShowRightARightTriangle:\n");
ShowRightARightTriangle(3);
Console.WriteLine("\nShowIsoscelesTriangleo:\n");
ShowIsoscelesTriangleo(3);
Console.WriteLine("\nShowCurve:\n");
ShowCurve(3);
}
private static void ShowLeftARightTriangle(int n)
{
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < i; j++)
{
Console.Write("*");
}
Console.Write("\n");
}
}
private static void ShowRightARightTriangle(int n)
{
for (int i = n; i > 0; i--)
{
for (int j = n - i; j < n - 1; j++)
{
Console.Write(" ");
}
for (int j = n - i + 1; j > 0; j--)
{
Console.Write("*");
}
Console.Write("\n");
}
}
private static void ShowIsoscelesTriangleo(int n)
{
for (int i = n; i > 0; i--)
{
for (int j = n - i; j < n - 1; j++)
{
Console.Write(" ");
}
for (int j = n - i + 1; j > 0; j--)
{
Console.Write("*");
}
for (int j = i; j < n; j++)
{
Console.Write("*");
}
Console.Write("\n");
}
}
private static void ShowCurve(int n)
{
for (int i = n; i > 0; i--)
{
for (int j = n - i; j < n - 1; j++)
{
Console.Write(" ");
}
Console.Write("*");
for (int j = n - i + 1; j > 1; j--)
{
Console.Write(" ");
}
for (int j = i; j < n - 1; j++)
{
Console.Write(" ");
}
if (i != n)
{
Console.Write("*");
}
if (i == 1)
{
for (int j = 2 * (n - 1); j > 1; j--)
{
Console.Write(" ");
}
Console.Write("*");
}
Console.Write("\n");
}
for (int i = 0; i < n - 1; i++)
{
for (int j = 2 * n - 1 + i; j > 0; j--)
{
Console.Write(" ");
}
Console.Write("*");
for (int j = 1; j < n - i - 2; j++)
{
Console.Write(" ");
}
for (int j = n - 2; j > i; j--)
{
Console.Write(" ");
}
if (i != n - 2)
{
Console.Write("*");
}
Console.Write("\n");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询