Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

새싹교실/2014/배반/6주차: Difference between revisions

From ZeroWiki
imported>woojin818
No edit summary
imported>minn951120
No edit summary
Line 25: Line 25:
=== 임기찬 ===
=== 임기찬 ===


=== 홍성현 ===


----
[[새싹교실/2014]] [[새싹교실/2014/배반]]
#include <stdio.h>
#include <stdio.h>
#define SIZE 10
#define SIZE 10


int MAP[[SIZE]][[SIZE]] = {0};
int MAP[[SIZE]][[SIZE]] = {0};
void PrintMap(int)
void PrintMap(int);
void Spin(int);


int main()
int main()
Line 40: Line 39:
printf("n을 입력해주세요");
printf("n을 입력해주세요");
scanf("%d",&n);
scanf("%d",&n);
Spin(n);
PrintMap(n);
return 0;
return 0;
}
}
Line 52: Line 53:
for(j = 0 ; j < n ; j++)
for(j = 0 ; j < n ; j++)
{
{
printf("%d",&map
printf("%d",MAP&#91;i&#93;&#91;j&#93;);
}
}
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&#91;x&#93;&#91;y&#93;=num;
y++;
num++;
}
SomeCount+=0.5;
AllCount--;
y--;
if(AllCount ==0)
break;
else if(AllCount ==1)
SomeCount--;
//아래쪽
for(i=0 ; i < (int)SomeCount ;)
{
MAP&#91;x&#93;&#91;y&#93;=num;
x++;
num++;
}
SomeCount+=0.5;
AllCount--;
x--;
if(AllCount ==0)
break;
else if(AllCount ==1)
SomeCount--;
//왼쪽
for(i=0 ; i < (int)SomeCount ;)
{
MAP&#91;x&#93;&#91;y&#93;=num;
y--;
num++;
}
SomeCount+=0.5;
AllCount--;
y++;
if(AllCount ==0)
break;
else if(AllCount ==1)
SomeCount--;
//위쪽
for(i=0 ; i < (int)SomeCount ;)
{
MAP&#91;x&#93;&#91;y&#93;=num;
x--;
num++;
}
SomeCount+=0.5;
AllCount--;
x++;
if(AllCount ==0)
break;
else if(AllCount ==1)
SomeCount--;
}
}
----
[[새싹교실/2014]] [[새싹교실/2014/배반]]



Revision as of 02:45, 21 May 2014

개요

내용

  • 포인터 --오세상에올것이왔어--
  • 망했다고 합니다. 이해하기 너무 힘든 듯.
  • 하지만 이번 주가 끝이 아니라고 합니다.후후후후후후후

과제

캡처.PNG Problem? --이 과제를 김승태교수님에게 바칩니다--

  • 단, 3~9 말고 3~11
  • 이거 하고
  • 할 수 있으면 배열을 통한 접근과 포인터를 이용한 접근 둘 다 해볼 것
  • 그리고 정수 대신에 주소값을 출력하는 것도 해볼 것
    • 이를 통해 주소값이 어떻게 배치되어 있는 지를 알 수 있음
  • 달팽이를 출력하는 부분은 꼭 함수로 만들 것.

제출 내용

임기찬

홍성현

  1. include <stdio.h>
  2. 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--; } }



새싹교실/2014 새싹교실/2014/배반