//C#控制台程序
static void Main(string[] args)
{
//Console.Write()
//输入一个数
bool ifNum = false;
string n_str = "";
int n = 0;
while (!ifNum)
{
n_str = Console.ReadLine();
try
{
n = int.Parse(n_str);
ifNum = true;
}
catch (FormatException)
{
ifNum = false;
}
}
//打印
char ch = 'A';
if (n != 0)
{
//打上面的三角形
for (int i = 0; i < n + 1; i++)
{
for (int j = 0; j < n - i; j++)
{
Console.Write(' ');
}
for (int j = 0; j < 2 * i + 1; j++)
{
Console.Write(ch);
ch++;
if (ch > 'Z')
{
ch = 'A';
}
}
Console.WriteLine();
}
//打下面的三角形
for (int i = n - 1; i > -1; i--)
{
for (int j = 0; j < n - i; j++)
{
Console.Write(' ');
}
for (int j = 0; j < 2 * i + 1; j++)
{
Console.Write(ch);
ch++;
if (ch > 'Z')
{
ch = 'A';
}
}
Console.WriteLine();
}
}
Console.ReadLine();
}
有问题再问