利用循环,输出* 希望给讲解下,
***
***
****
*****
利用C#循环语句输出上面的内容
求指教, 必须是循环..
程序代码:using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication14
{
class Program
{
public static int NUMBER;
static void Main(string[] args)
{
Console.WriteLine("输出行数:");
string str = Console.ReadLine();
try
{
NUMBER = int.Parse(str) + 1;
PrintStar(NUMBER-1);
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
private static void PrintStar(int num)
{
if (num == 0)
return;
int starNum = NUMBER - num;
for (int i = 1; i <= starNum; i++)
{
Console.Write("* ");
}
Console.Write("\n");
PrintStar(num - 1);
}
}
}
