编程: 输入n的值,输出由*组成的菱形?(过程详细点)
用c#写的程序:
Console.WriteLine("请输入一个奇数字");
int num = Convert.ToInt32(Console .ReadLine ());
for (int i = 1; i <= (num + 1) / 2; i++)
{
for (int j = 1; j <= (num - (2 * i - 1)) / 2; j++)
{ Console.Write(" "); }
for (int k = 1; k <= 2 * i - 1; k++)
{ Console.Write("*"); }
Console.WriteLine();
}
for (int i = 1; i < (num + 1) / 2; i++)
{
for (int j = 1; j <= i; j++)
{ Console.Write(" "); }
for (int k = 1; k <= num - 2 * i; k++)
{ Console.Write("*");}
Console .WriteLine ();
}
Console.ReadKey();
2024-11-19 广告