#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
int i,j;
scanf("%d",&n);
int row = 1 << n;
int* arr = (int*)malloc(row*n*sizeof(int));
for(i=0;i<row;++i)
{
for(j=0;j<n;j++)
{
if((i>>j)&1)
{
*(arr+i*n+n-j-1) = 1;
}
else
{
*(arr+i*n+n-j-1) = 0;
}
}
}
for(i=0;i<row;i++)
{
for(j=0;j<n;j++)
{
printf("%2d ",*(arr+i*n+j));
}
putchar('\n');
}
free(arr);
return 0;
}
转载于:https://blog.51cto.com/yongjiuzhizhen/1320576