华剑缘 一切都在这个过程中获得，将那些目标埋藏于心中

#include  " iostream.h "

int  main()
{

int  N,i,j,count;
cout
<< " Please enter N: " ;
cin
>> N;

int   ** arr = new   int *  [N];

for (i = 0 ;i < N;i ++ )
arr[i]
= new   int [N];

for (i = 0 ;i < N;i ++ )

for (j = 0 ;j < N;j ++ )
arr[i][j]
= 0 ;
arr[
0 ][(N + 1 ) / 2 - 1 ] = 1 ;

for (count = 1 ,i = 0 ,j = (N + 1 ) / 2 - 1 ;count < N * N;count ++ )

{
i
-- ;
j
-- ;

if (i ==- 1 )
i
= N - 1 ;

if (j ==- 1 )
j
= N - 1 ;

if (arr[i][j] == 0 )
arr[i][j]
= count + 1 ;

else   if (arr[i][j] > 0 )

{
i
= i + 2 ;
j
= j + 1 ;

if (j == N)
j
= 0 ;

if (i == N)
i
= 0 ;

else   if (i == N + 1 )
i
= 1 ;
arr[i][j]
= count + 1 ;
}

}

for (i = 0 ;i < N;i ++ )

{

for (j = 0 ;j < N;j ++ )

{
cout
<< arr[i][j] << "   " ;
}

cout
<< " \n " ;
}

for (i = 0 ;i < N;i ++ )
delete [] arr[i];
delete [] arr;

return   1 ;
}
posted on 2006-04-09 22:58 华剑缘 阅读(322) 评论(3)  编辑 收藏 引用

FeedBack:
# re: 幻方，呵呵学习学习
2006-04-10 09:03 | 沐枫
int ** arr = new int * [N];
for (i = 0 ;i < N;i ++ )
arr[i] = new int [N];
for (i = 0 ;i < N;i ++ )
for (j = 0 ;j < N;j ++ )
arr[i][j] = 0 ;

# re: 幻方，呵呵学习学习
2006-04-10 12:27 | 华剑缘

# re: 幻方，呵呵学习学习
2006-04-14 17:31 | 华剑缘
@沐枫
@沐枫
c:\documents and settings\kakaxi\桌面\新建文件夹\text1.cpp(12) : error C2065: 'for_each' : undeclared identifier
c:\documents and settings\kakaxi\桌面\新建文件夹\text1.cpp(12) : error C2065: 'bind2nd' : undeclared identifier
c:\documents and settings\kakaxi\桌面\新建文件夹\text1.cpp(12) : error C2065: 'mem_fun_ref' : undeclared identifier  回复  更多评论