C#控制台程序:
目标三角形
*
***
*****
***
*
要求是奇数行哦
------解决方案--------------------------------------------------------
Console.Write("请输入要打印三角形的行数:");
int nums = int.Parse(Console.ReadLine());
for (int i = 0; i < nums;i++)
{
for (int j=0;j<nums-i;j++) //打印空格
{
Console.Write(" ");
}
for (int k=0;k<=i;k++) //以打印*号来代替边
{
Console.Write("* ");
}
}
------解决方案--------------------------------------------------------
- C# code
for (int i = 0; i < 4; i++) { for (int j = 0; j < 1+2*i; j++) { Console.Write("*"); } Console.WriteLine(); } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3 - i; j++) { Console.Write("*"); } Console.WriteLine(); } Console.ReadLine();