마방진 크기가 5인 정방
기쁨해
마방진 수치오류왜 값이 25를 초과하지는지 모르겠습니다.질문 내용 :
어디가 잘못됬나요? 책에 나온 코드 그대로 타이핑했는데 해결이 안돼네요.
#include stdio.h
#define max_size 5
void main(void){
int square[max_size][max_size];
int i, j, row, column;
int count;
int size;
printf(enter the size of the square:);
scanf(%d, &size);
if(size1||sizemax_size){
fprintf(stderr,error! size is out of range\n);
exit(1);
}
if(!(size%2)){
fprintf(stderr,error! size is even\n);
exit(1);
}
for(i=0; isize; i++)
for(j=0; jsize; j++)
square[i][j]=0;
square[0][(size-1)/2]=1; //泥ル쾲吏??됱쓽 以묒옣??1???k뒗??
i=0;
j=(size-1)/2;
for(count =2; count=size*size; count++){
row = (i-10)? (size-1): (i-1); //?꾨줈
column=(j-10)? (size-1): (j-1); //?쇱そ
if(square[row][column]) //?꾨옒濡?
i=(++i) % size;
else{
i=row;
j=(j-10) ? (size-1): --j;
}
square[i][j]=count;
}
printf(magic square of ize %d:\n\n, size);
for(i=0; i size; i++){
for(j=0; jsize; j++)
printf(%d5 , square[i][j]);
printf(\n);
}
printf(\n\n);
system(pause);
}
-
맑은누리
책 그래도 써서 코드를 짰는데 원하는 결과가 안나오네요.
-
들찬길
오류에요. 리눅스에서 코딩하다가 윈도우에서 주석처리된거 돌리다가 인코딩이 안 맞은것 같은데여.
-
큰나라
설마 책에 \//泥ル쾲吏??됱쓽 以묒옣??1???k뒗??\ 이렇게 나와 있을라고요.