| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

i = 1   0 0 0 0 0 0 0 0 0
i = 2   0 0 0 0 1 1 0 0 0
i = 3   0 0 0 1 0 0 1 0 0
i = 4   0 0 0 1 1 1 1 0 0
i = 5   0 0 1 0 0 0 0 1 0
i = 6   0 0 1 0 1 1 0 1 0
i = 7   0 0 1 1 0 0 1 1 0
i = 8   0 0 1 1 1 1 1 1 0
i = 9   0 1 0 0 0 0 0 0 1
i = 10  0 1 0 0 1 1 0 0 1
i = 11  0 1 0 1 0 0 1 0 1
i = 12  0 1 0 1 1 1 1 0 1
i = 13  0 1 1 0 0 0 0 1 1
i = 14  0 1 1 0 1 1 0 1 1
i = 15  0 1 1 1 0 0 1 1 1
i = 16  0 1 1 1 1 1 1 1 1
规律：这里有16个一维数组，每行为一个一维数组，每个数组有9个数，第一个数都为0，单独看 每个一维数组，没有啥规律，现在把这16个一维数组放在一起来看就成了一个16行的二维数组。

```#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[9];
FILE *fp;
if ((fp = fopen ("D:\\a9.txt", "a+")) == NULL)
{
printf("打开文件失败\n");
exit(1);    }
for(int i = 0; i < 16 ; i++)
{
int n = i ;
int m = i ;
fprintf(fp,"i = %d \n",i);
for ( int j = 1; j<10; ++j)
{
a[j]=j;
fprintf(fp, "%3d ",a[j]);
}
fprintf(fp,"\n");

for(int j = 1; j < 5; j++)
{

a[j]=(n&1);
fprintf(fp, "%3d ", a[j]);

fprintf(fp,"\n");
n = n>>1;
}
for(int j = 5; j < 9; j++)
{
a[j]=!!(m&8);
fprintf(fp, "%3d ", a[j]);
fprintf(fp,"\n");
m = m<<1;
}

}
fclose(fp);
return 0;
}```

#include <stdio.h>
int main()
{
int a[8];
FILE *fp;
if ((fp = fopen ("D:\\a9.txt", "w+")) == NULL)
{
printf("打开文件失败\n");
exit(1);
}
for(int i = 0; i < 16 ; i++)
{
fprintf(fp,"i = %-2d   0",i+1);
for ( int j=0; j<4; ++j)
{
a[3-j] = (i>>j)&1;
a[j+4] = a[3-j];
}
for ( int j=0; j<8; ++j)
fprintf(fp, "%3d ",a[j]);
fprintf(fp,"\n");
}
fclose(fp);
return 0;
}

exit(1);缺少头文件#include <stdlib.h> 。加上就OK。

```#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[9];
FILE *fp;
if ((fp = fopen ("D:\\a9.txt", "w+")) == NULL)
{
printf("打开文件失败\n");
exit(1);
}
a[0]=0;
for(int i = 1; i < 17 ; i++)
{
fprintf(fp,"i = %d  ",i);

for ( int j=0; j<4; ++j)
{
a[4-j] = ((i-1)>>j)&1;
a[j+5] = a[4-j];
}
for ( int j=0; j<9; ++j)
fprintf(fp, "%3d ",a[j]);
fprintf(fp,"\n");
}
fclose(fp);
return 0;
}```

• 5
• 1/1页
• 1