群里的一朋友给的,实现的很精巧,放到这里备忘。
代码如下:
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>");
}
}
}
输出结果: