달팽이 배열 주석좀 달아주세요~~
잔디
2023.04.01
주석달아주새요 ㅠㅠ이해가 안가서요ㅜㅜ 자세히 이게이렇게 쓰여서 이런 결과가 나온거다 이렇게요질문 내용 :
#include stdio.h
int main()
{
int cnt=1;
int i;
int a,b;
int n=5;
int m=5;
int sw=1;
int x=-1,y=0;
int arr[5][5];
while(cnt=n*n)
{
for(i=1;i=m;i++)
{
x=x+sw;
arr[x][y]=cnt;
cnt++;
}
m--;
for(i=1;i=m;i++)
{
y=y+sw;
arr[x][y]=cnt;
cnt++;
}
sw=-sw;
}
for (b=0; bn; b++)
{
for (a=0; an; a++)
{
printf(%3d, arr[a][b]);
}
printf(\n);
}
return 0;
}