| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2378 人关注过本帖
标题:魔方阵
取消只看楼主 加入收藏
白居易
Rank: 1
来 自:北京
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-5-28
收藏
 问题点数:0 回复次数:2 
魔方阵

#include <stdio.h>
void main()
{
int array[16][16];
int i,j,k,m,n;
m=1;
while(m==1)
{
printf("请输入n(0<n<=15),n是奇数)\n");
scanf("%d",&n);
if(n!=0)&&(n<=15)&&(n%2!=0))
{
printf("矩形阶数是%d\n",n);
m=0;
}
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
array[i][j]=0;
j=n/2+1;
array[1][j]=1;
for(k=2;k<=n*n;k++)
{
i=i-1;
j=j+1;
if((i<1)&&(j>n))
{
i=i+2;
j=j-1;
}
else
{
if(i<1)
i=n;
if(j>n)
j=1;
}
if(array[i][j]==0)
array[i][j]=k;
else
{
i=i+2;
j=j-1;
array[i][j]=k;
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%5d",array[i][j];
printf("\n");
}
}
此程序不知那里有问题
-------------------Configuration: 魔方阵 - Win32 Debug--------------------
Compiling...
魔方阵.c
D:\软件\程序包\魔方阵.c(11) : error C2143: syntax error : missing ';' before '&&'
D:\软件\程序包\魔方阵.c(17) : error C2059: syntax error : 'for'
D:\软件\程序包\魔方阵.c(17) : error C2143: syntax error : missing '{' before '<='
D:\软件\程序包\魔方阵.c(17) : error C2059: syntax error : '<='
D:\软件\程序包\魔方阵.c(17) : error C2143: syntax error : missing '{' before '++'
D:\软件\程序包\魔方阵.c(17) : error C2059: syntax error : '++'
D:\软件\程序包\魔方阵.c(17) : error C2059: syntax error : ')'
D:\软件\程序包\魔方阵.c(18) : error C2143: syntax error : missing '{' before '<='
D:\软件\程序包\魔方阵.c(18) : error C2059: syntax error : '<='
D:\软件\程序包\魔方阵.c(18) : error C2143: syntax error : missing '{' before '++'
D:\软件\程序包\魔方阵.c(18) : error C2059: syntax error : '++'
D:\软件\程序包\魔方阵.c(18) : error C2059: syntax error : ')'
D:\软件\程序包\魔方阵.c(20) : error C2065: 'n' : undeclared identifier
D:\软件\程序包\魔方阵.c(20) : error C2099: initializer is not a constant
D:\软件\程序包\魔方阵.c(21) : error C2057: expected constant expression
D:\软件\程序包\魔方阵.c(21) : error C2466: cannot allocate an array of constant size 0
D:\软件\程序包\魔方阵.c(21) : error C2087: '<Unknown>' : missing subscript
D:\软件\程序包\魔方阵.c(21) : error C2075: 'array' : array initialization needs curly braces
D:\软件\程序包\魔方阵.c(22) : error C2059: syntax error : 'for'
D:\软件\程序包\魔方阵.c(22) : error C2143: syntax error : missing '{' before '<='
D:\软件\程序包\魔方阵.c(22) : error C2059: syntax error : '<='
D:\软件\程序包\魔方阵.c(22) : error C2143: syntax error : missing '{' before '++'
D:\软件\程序包\魔方阵.c(22) : error C2059: syntax error : '++'
D:\软件\程序包\魔方阵.c(22) : error C2059: syntax error : ')'
D:\软件\程序包\魔方阵.c(47) : error C2059: syntax error : 'for'
D:\软件\程序包\魔方阵.c(47) : error C2143: syntax error : missing '{' before '<='
D:\软件\程序包\魔方阵.c(47) : error C2059: syntax error : '<='
D:\软件\程序包\魔方阵.c(47) : error C2143: syntax error : missing '{' before '++'
D:\软件\程序包\魔方阵.c(47) : error C2059: syntax error : '++'
D:\软件\程序包\魔方阵.c(47) : error C2059: syntax error : ')'
D:\软件\程序包\魔方阵.c(53) : error C2059: syntax error : '}'
执行 cl.exe 时出错.

魔方阵.obj - 1 error(s), 0 warning(s)

搜索更多相关主题的帖子: 魔方 
2007-10-13 23:51
白居易
Rank: 1
来 自:北京
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-5-28
收藏
得分:0 

C语言真是马虎不得,多谢!!!编译通过了


革命尚未成功,同志仍需努力
2007-10-14 17:04
白居易
Rank: 1
来 自:北京
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-5-28
收藏
得分:0 
回复:(wolf777)魔方阵能解释下是什么编程问题?
所谓魔方阵,是指每一行、每一列经及对角线之和均相等,最大阶数只能为15,所以定义数组为16行16列,对第0行第0列不存在数据,而是从第1行第1列开始存放数,以符合读者的习惯。
规则如下:
(1)将1放在第一行中间的一列;
(2)从2开始直到N*N为止,各数依次按照下列规则存放:每一个数字存放的行比前一个数的行数减一,列数加一;
(3)如果上一个数的行数为1时,则下一个数的行数为N(即最下一行);
(4)当上一个数的列数为N,下一个数的列数应该为1,行数减一;
(5)如果按照上面规则确定的位置上已有数,或者上一个数是第1行第N列时,则把下一个数放在上一个数的下面。

革命尚未成功,同志仍需努力
2007-10-15 20:03
快速回复:魔方阵
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016597 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved