지금 졸라 신나서

여기 올리고 정답보러갈거임

으희

아무것도 안보고 혼자서만듦


근뎀 동적할당이 뭐임???

나처럼 2차원배열에다가 무식하게 때려박으면 안댐??


--

#include <stdio.h>


void GetSqrLength(int *SqrLength);

void RgstrtnNum(int iArr[][30], int SqrLength);

void PrintArr(int iArr[][30], int SqrLength);


int main(void)

{

int iArr[30][30] = {0}; //배열

int SqrLength = 0; //배열의 한 변의 길이


GetSqrLength(&SqrLength);

RgstrtnNum(iArr, SqrLength);

PrintArr(iArr, SqrLength);


return;

}


/*달팽이 배열의 한 변의 길이를 구한다*/

void GetSqrLength(int *SqrLength)

{

printf("달팽이 배열의 한 변의 길이를 입력하시오.");

scanf("%d", SqrLength);

return;

}


/*달팽이 모양으로 배열을 채운다*/

void RgstrtnNum(int iArr[][30], int SqrLength) //SqrLength : 남은거리

{

int Row = 0; //행 단위 기록

int Column = 0; //열 단위 기록

int iCount = 0; //배열 안에 넣을 수

int i = 0; //반복

SqrLength--;


iCount++;

iArr[0][0] = 1;


for(i = 0; i < SqrLength; i++) {

Column++;

iCount++;

iArr[Column][Row] = iCount;

} //end for

while(SqrLength > 0) {

for(i = 0; i < SqrLength; i++) {

Row++;

iCount++;

iArr[Column][Row] = iCount;

} //end for


for(i = 0; i < SqrLength; i++) {

Column--;

iCount++;

iArr[Column][Row] = iCount;

} //end for


SqrLength--;


for(i = 0; i < SqrLength; i++) {

Row--;

iCount++;

iArr[Column][Row] = iCount;

} //end for


for(i = 0; i < SqrLength; i++) {

Column++;

iCount++;

iArr[Column][Row] = iCount;

} //end for

SqrLength--;

} //end while


return;

}


/*달팽이배열 출력*/

void PrintArr(int iArr[][30], int SqrLength)

{

int Row = 0; //행단위

int Column = 0; //열단위


//배열 출력

for(Row = 0; Row < SqrLength; Row++) {

for(Column = 0; Column < SqrLength; Column++) {

printf("%-3d", iArr[Column][Row]);

} //end inner for

printf(" ");

} //end outer for


return;

}