利用循环,输出* 希望给讲解下,
***
***
****
*****
利用C#循环语句输出上面的内容
求指教, 必须是循环..
2009-11-04 19:56
2009-11-04 20:19
2009-11-04 23:40
程序代码: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);
}
}
}

2009-11-04 23:58
2009-11-05 16:38
2009-11-06 10:08
2009-11-08 00:26
2009-11-08 19:11
2009-11-09 09:10