一 编程思想构建
利用数学归纳法找规律
二 找到规律后利用vs控制台编写程序
总程序:
Console.WriteLine("请输入等边三角形高度:");
string line = Console.ReadLine();
int height = 3;
if (false == int.TryParse(line, out height))
{
Console.WriteLine("输入高度不是合法整数,默认高度3执行");
}
for (int h = 0; h < height; h++)
{
for (int idx = 0; idx <= 2 * height - 1; idx++)
{
if (idx > height - h - 1 && idx <= height - h - 1 + 2 * h + 1)
{
Console.Write("*");
}
else
{
Console.Write(" ");
}
}
Console.WriteLine();
}