More actions
개요
내용
- 포인터 --오세상에올것이왔어--
- 망했다고 합니다. 이해하기 너무 힘든 듯.
- 하지만 이번 주가 끝이 아니라고 합니다.후후후후후후후
과제
캡처.PNG Problem? --이 과제를 김승태교수님에게 바칩니다--
- 단, 3~9 말고 3~11
- 이거 하고
- 할 수 있으면 배열을 통한 접근과 포인터를 이용한 접근 둘 다 해볼 것
- 그리고 정수 대신에 주소값을 출력하는 것도 해볼 것
- 이를 통해 주소값이 어떻게 배치되어 있는 지를 알 수 있음
- 달팽이를 출력하는 부분은 꼭 함수로 만들 것.
제출 내용
임기찬
홍성현
- include <stdio.h>
- define SIZE 10
int MAPSIZESIZE = {0}; void PrintMap(int); void Spin(int);
int main() { int n; printf("n을 입력해주세요"); scanf("%d",&n); Spin(n); PrintMap(n); return 0; }
void PrintMap(int n) { int i,j; i=j=n;
for(i = 0 ; i < n ; i++) { for(j = 0 ; j < n ; j++) { printf("%d",MAP[i][j]); } printf("\n"); } }
void Spin(int n) { int i,j,k,AllCount,x,y,num=1 ; float SomeCount =1.0;
if(n%2==1) k=n/2; else k=n/2 -1;
x=0,y=0; while(1) { //오른쪽 for(i=0 ; i < (int)SomeCount ;) { MAP[x][y]=num; y++; num++; } SomeCount+=0.5; AllCount--; y--; if(AllCount ==0) break; else if(AllCount ==1) SomeCount--;
//아래쪽 for(i=0 ; i < (int)SomeCount ;) { MAP[x][y]=num; x++; num++; } SomeCount+=0.5; AllCount--; x--; if(AllCount ==0) break; else if(AllCount ==1) SomeCount--;
//왼쪽 for(i=0 ; i < (int)SomeCount ;) { MAP[x][y]=num; y--; num++; } SomeCount+=0.5; AllCount--; y++; if(AllCount ==0) break; else if(AllCount ==1) SomeCount--;
//위쪽 for(i=0 ; i < (int)SomeCount ;) { MAP[x][y]=num; x--; num++; } SomeCount+=0.5; AllCount--; x++; if(AllCount ==0) break; else if(AllCount ==1) SomeCount--; } }