标签:printf for else pre code return scanf ++ down
#include <stdio.h>
#define N 1000
int num[N];
void gray(int n)
{
int k,i;
if(n==1)
{num[0]=0;num[1]=1;return;}
gray(n-1);
k=1<<(n-1);
for(i=0;i<k;++i)
num[i+k]=num[k-1-i]+k;
}
void out(int n)
{
int k,i,j,m;
int count=0;
k=1<<n;
for(i=0;i<k;++i)
{
count++;
//printf("%d ",count);
if(count>8)
{
//printf("%d",count);
printf("\n");
count=1;
}
for(j=n;j>0;--j)
{
m=1<<(j-1);
//printf("%d %d\n",m,num[k]);
if(num[i]>=m)
{
printf("1");
num[i]-=m;
}
else printf("0");
}
printf(" ");
}
}
void out2(int n)
{
int k,i;
k=1<<n;
for(i=0;i<k;++i)
printf("%d ",num[i]);
printf("\n");
}
int main()
{
int n;
while(scanf("%d",&n),n)
{
gray(n);
out(n);
printf("\n");
}
return 0;
}
标签:printf for else pre code return scanf ++ down
原文地址:http://www.cnblogs.com/qichunlin/p/7892578.html