杨辉三角简单示例

 

 static void Main(string[] args)
        {
            /*
             *
             *  1
             *  1  1
             *  1  2  1
             *  1  3  3  1
             *  1  4  6  4  1
             *  1  5  10 10  5  1
             */          
            int[,]arry=new int[6,6];
            for (int i = 0; i < 6; i++)
            {
                arry[i, 0] = 1;
                arry[i, i] = 1;
                for (int j = 1; j < i+1; j++)
                {
                 arry[i,j]=arry[i-1,j-1]+arry[i-1,j];                 
                }
            }
            for(int i=0;i<6;i++)
            {
                for(int j=0;j<=i;j++)
                {
                    Console.Write(arry[i,j]+" ");
                }
                Console.WriteLine();
            }


        }

运行结果:

posted @ 2012-02-27 15:51  木子易  Views(168)  Comments(0Edit  收藏  举报