求C#程序 输入不同的数字,输出相应的菱形
展开全部
do
{
try
{
Console.Clear();
int size = Convert.ToInt32(Console.ReadLine());
for (int rowNum = 0; rowNum < size; rowNum++)
{
string rowTxt = string.Empty;
for (int colNum = 0; colNum < size; colNum++)
{
bool valid =
(rowNum + colNum == (size + 1) / 2 - 1) ||
(rowNum + colNum == size + size / 2 - 1) ||
(Math.Abs(rowNum - colNum) == size / 2);
rowTxt += valid ? " " : "■";
}
Console.WriteLine(rowTxt);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("按Esc退出...");
}
while (Console.ReadKey().Key != ConsoleKey.Escape);
//不用谢,我只是闲的慌
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询