#include <stdio.h>
int main()
{
int n, input, i = 0, j = 0, temp = 0, turn = 1, count = 1;
int arr[100][100];
printf("한변의 크기가 몇인 달팽이 배열을 만들겠습니까? ");
scanf("%d", &input);
n = input;
while (count != n*n)
{
if (turn == 1)
{
for (i = temp, j = temp; j < n-temp; j++)
arr[i][j] = count++;
j = n - temp - 1;
if (count != n*n)
break;
for (i = temp + 1,j=n-1-temp; i < n-temp; i++)
arr[i][j] = count++;
turn *= (-1);
}
else if (turn == -1)
{
for (i = n - temp - 1, j = n - temp - 2; j >= temp; j--)
arr[i][j] = count++;
if (count != n*n)
break;
for (i = n - temp - 2, j = temp; i > temp; i--)
arr[i][j] = count++;
temp++;
turn *= (-1);
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
printf("%d ", arr[i][j]);
printf("\n");
}
return 0;
}
5입력시
1 2 3 4 5
16 17 17 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
나오게 하는거라는데 직접 노트에서 순서대로 적으면 잘되는거 같은데
컴파일만 하면 왜
1 2 3 4 5
-858993460 -858993460 -858993460 -858993460 -858993460
-858993460 -858993460 -858993460 -858993460 -858993460
-858993460 -858993460 -858993460 -858993460 -858993460
-858993460 -858993460 -858993460 -858993460 -858993460
이렇게 나올까요?
도움이 필요합니다~
F10 계속 눌러바 - dc App
해결완~~
감사합니다 갤러님들 count!=이 잘못이였네요 count==로했었어야햇음
근데 f10은 뭐임
아 단계별 디버깅이군여 감사
리얼 프갤에 올리면 뭐가틀렷는지 바로 눈에보이네 충성충성
노무현 개새끼 ㅇㅅㅇ