群里的一朋友给的,实现的很精巧,放到这里备忘。

代码如下:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //设定层数
        int n = 4;
 
        int nn = 1 << (n * 2);
        for (int i = 0; i < nn; i++)
        {
            for (int j = n - 1; j >= 0; j--)
            {
                int tt = (i >> (n + j)) % 2 * 2 + ((i % (1 << n)) >> j) % 2 + 1;
                Response.Write((i >> (n + j)) % 2 * 2 + ((i % (1 << n)) >> j) % 2 + 1);
 
            }
            Response.Write(" ");
            if ((i + 1) % (1 << n) == 0)
                Response.Write("<br>");
        } 
    }
}

输出结果:

下载地址:https://files.cnblogs.com/reonlyrun/Tile_Pyramid.rar

Posted on 2007-04-13 16:46  Clark Zheng  阅读(3162)  评论(5编辑  收藏  举报