프로그래밍 질문좀요..
초코홀릭
#includestdio.h
void output(); //출력 ㅇㅇ
void holprocess(); //왼쪽 아래로 가는거
void jjakprocess(); // 오른쪽 위로 가는거
void leftcrash(); //왼쪽충돌
void rightcrash(); // 오른쪽충돌 이게 문제야
void topcrash(); // 위충돌
void undercrash(); //아래충돌
void calc(); // 계산
int arr[100][100]; //2차원 배열
int input; // 입력받을거
int x,y; //뺑뺑이 돌릴거
int num = 1; //수
void main()
{
freopen(input.txt,r,stdin);
freopen(output.txt,w,stdout);
scanf(%d,&input);
arr[x][y] = num;
num++;
while(num = input * input) // 수가 input의 제곱 넘을때 까지
{
while((x + y + 1) % 2 != 0)
{
holprocess();
if(y 0)
{
leftcrash();
if(x == input)
{
undercrash();
calc();
break;
}
calc();
break;
}
calc();
break;
}
while((x + y + 1) % 2 == 0)
{
jjakprocess();
if(x 0)
{
if(y == input)
{
rightcrash();
calc();
break;
}
topcrash();
if(y == input)
{
rightcrash();
calc();
break;
}
calc();
break;
}
calc();
break;
}
}
output();
}
void output()
{
for(x = 0;x input; x++)
{
for(y = 0; y input
; y++)
{
printf(%d ,arr[x][y]);
}
printf(\n);
}
}
void holprocess()
{
x++;
y--;
}
void jjakprocess()
{
x--;
y++;
}
void leftcrash()
{
y = 0;
}
void topcrash()
{
x = 0;
}
void undercrash()
{
x = input - 1;
y++;
}
void rightcrash()
{
y = input - 1;
x++;
}
void calc()
{
arr[x][y] = num;
num++;
}
대각선지그재그..출력하는 프로그램인데요...
원래는 3 입력하면
1 3 4
2 5 8
6 7 9
2입력하면
1 3
2 4
이렇게 지그재그로 출력되야하는데
제꺼는
1 3 4
2 5 8
6 7 0 이출력되네요..
제 나름대로 분석해봤는데 rightcrash() 이함수를 제대로 호출하지 못하고 있는듯 해요
그에 따른 if문의 조건도 잘 못설정하겠고.. 불쌍한 어린양에게 조언을 좀..