楊輝三角C#版

class Program
{
static void Main(string[] args)
{
Console.WriteLine("please input a number:");
int n =int.Parse ( Console.ReadLine());
int [,] c=new int[n,n];
c[0, 0] = 1;
//c[0, 1] = 1;
for(int i=1;i<n;i++)
{
c[i, 0] = 1;
for (int j=1;j<=i;j++)
{
//if (j==0 || j==i || i==0)
//{
// c[i,j]=1;
//}
//else {
c[i,j]=c[i-1,j-1]+c[i-1,j];
//}

}

}
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= i; j++)
{
Console.Write(c[i, j]);
Console.Write(" ");
}
Console.Write("\r\n");
}
Console.ReadKey();
}
}

猜你喜欢

转载自www.cnblogs.com/xychen/p/PascalTriangle.html
今日推荐