求高手帮忙调程序啊!!!!
#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 19/*the max size of magic square is 19*/
void main (void)
{
static int square[MAX_SIZE][MAX_SIZE];
int i,j,row,column;/*search*/
int count;/*count*/
int size;/*size of the magic square*/
printf("Enter the size of the magic square:\n");
scanf("%d",&size);
/*check the size*/
if(size<1||size>MAX_SIZE+1)
{
printf("error,the size is out of range!Please enter size again.\n ");
}
for(i=1;i<size;i++)
for(j=0;j<size;j++)
square[i][j]=0;
square[0][(size-1)/2]=1;/*the middle of the first line is 1*/
i=0;
j=(size-1)/2;
for(count=2;count<=size*size;count++)
{
row=(i-1<0)?(size-1):(i-1);/*up*/
column=(j-1<0)?(size-1):(j-1);/*left*/
if(square[row][column])/*down*/
i=(++i)%size;
else
{
i=row;
j=(j-1<0?(size-1):--j);
}
square[i][j]=count;
}
/*printf the magic square*/
printf("Magic square of size %d:\n\n",size);
for (i=1;i<size;i++)
{
for (j=0;j<size;j++)
printf("%5d",square[i][j]);
printf("\n");
}
printf("\n\n");
system("pause");
}
这个幻方程序,小弟我怎么改起始行都没有办法正常显示,也就是缺失起始行,求各位高手不吝赐教,小弟拜谢了!
[解决办法]
for (i=1;i<size;i++)
应该是
for (i=0;i<size;i++)