#include<stdio.h>
#define N 9
int main()
{
FILE *fp;
if ((fp = fopen("magic.txt", "w")) == NULL)
{
printf("fail");
return 1;
}
int i, j, nn, sum1 = 0, sum2 = 0,sum3=0,sum4=0;
int a[N][N] = { 0 };
i = 0;
j = N / 2;
for (nn = 1; nn <= N*N; nn++)
{
a[i][j] = nn;
i -= 1;
if (i < 0)i = N - 1;
j += 1;
if (j == N)j = 0;
if (a[i][j] != 0)
{
i += 2;
if (i == N)i = 0;
if (i == N + 1)i = 1;
j -= 1;
if (j < 0)j = N - 1;
}
}
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余2页未读,立即下载