该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include "stdlib.h"
#include "stdio.h"
int main()
{
int arr[3][3] = {0};
int i,j;
int k;
int temp;
int t = 0;
i = 0;
j = 1;
arr[0][1] = 1;
for(k = 2;k <= 9;k++)
{
i = i - 1;
j = j + 1;
if((k - 1) % 3 == 0)/*如果当前数是三的倍数*/
{
i = i + 2; /*把下一个数放到当前数正下方*/
j = j - 1; /*坐标位置为i+1,j*/
}
if(i
if(j > 2) j = 0;/*如果当前位置在最后一列,下一个数放到第一列*/
arr[i][j] = k;
}
printf("\n");
while(t<2){
for(j = 0;j
{
temp = arr[0][j];
arr[0][j] = arr[2][j];
arr[2][j] = temp;
}
for(i = 0;i
{
for(j = 0;j
printf("%d ",arr[i][j]);
printf("\n");
}
printf("\n");
for(i = 0;i
{
temp = arr[i][0];
arr[i][0] = arr[i][2];
arr[i][2] = temp;
}
for(i = 0;i
{
for(j = 0;j
printf("%d ",arr[i][j]);
printf("\n");
}
printf("\n");
t++;
}
for(i = 0;i
for(j = 0;j
{
temp = arr[i][j];
arr[i][j] = arr[j][i];
arr[j][i] = temp;
}
while(t<4){
for(j = 0;j
{
temp = arr[0][j];
arr[0][j] = arr[2][j];
arr[2][j] = temp;
}
for(i = 0;i
{
for(j = 0;j
printf("%d ",arr[i][j]);
printf("\n");
}
printf("\n");
for(i = 0;i
{
temp = arr[i][0];
arr[i][0] = arr[i][2];
arr[i][2] = temp;
}
for(i = 0;i
{
for(j = 0;j
printf("%d ",arr[i][j]);
printf("\n");
}
printf("\n");
t++;
}
system("pause");
}
3阶魔方阵的全部解,搞完了哈哈,