www.pudn.com > DigitalPyramid.rar > 编写程序,实现数字金字塔.txt, change:2010-12-29,size:1091b


编写程序,实现数字金字塔 
 
using System; 
namespace test 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            int i, j, k; 
            k = 9; 
            int[][] Y = new int[k][]; 
            for (i = 1; i <= Y.Length; i++) 
            { 
                Y[i-1] = new int[i * 2 - 1]; 
                for (j = 1; j <= i * 2 - 1; j++) 
                { 
                    if (j <= i) Y[i-1][j-1] = j; 
                    else Y[i-1][j-1] = i - j % i; 
                } 
            } 
 
            string[] PreStr = new string[k]; 
            for(i = 0; i < PreStr.Length; i++)  
            { 
                for (j = 0; j < 20 - i; j++) 
                { 
                    PreStr[i] += " "; 
                } 
            } 
 
            for (i = 0; i < Y.Length; i++) 
            { 
                Console.Write(PreStr[i]); 
                for (j = 0; j < Y[i].Length; j++) 
                    Console.Write(Y[i][j]); 
                Console.WriteLine(); 
            } 
            Console.ReadKey(); 
        } 
    } 
}