More actions
imported>jediweon No edit summary |
(Repair batch-0005 pages from live compare) |
||
| (10 intermediate revisions by 5 users not shown) | |||
| Line 2: | Line 2: | ||
== 개요 == | == 개요 == | ||
* [[원준연]],[[임기찬]],[[최필립]],[[홍성현]] | * [[원준연]],[[임기찬]],[[최필립]],[[홍성현]] | ||
* 진행 일시 : 5월 7일 15:00~16:15 | |||
== 내용 == | == 내용 == | ||
| Line 11: | Line 12: | ||
[[:File:새싹교실__2014__배반__6주차__캡처.PNG|캡처.PNG]] | [[:File:새싹교실__2014__배반__6주차__캡처.PNG|캡처.PNG]] | ||
'''Problem?''' | '''Problem?''' | ||
--이 과제를 김승태교수님에게 바칩니다-- | |||
* 단, 3~9 말고 3~11 | * 단, 3~9 말고 3~11 | ||
| Line 18: | Line 20: | ||
** 이를 통해 주소값이 어떻게 배치되어 있는 지를 알 수 있음 | ** 이를 통해 주소값이 어떻게 배치되어 있는 지를 알 수 있음 | ||
* 달팽이를 출력하는 부분은 꼭 함수로 만들 것. | * 달팽이를 출력하는 부분은 꼭 함수로 만들 것. | ||
== 제출 내용 == | |||
=== 최필립 === | |||
*--아는 다른학교 컴공애가 아이디어 제공을 안쓰럽다고 조큼 도와줌-- | |||
*주소값 출력은 그냥 printf 뒤에 &만 | |||
#include <stdio.h> | |||
void show(); | |||
int i,j; | |||
int num=1,k,move=-1, temp, l,m; | |||
int size; | |||
int array[11][11]={0,}; | |||
int main() | |||
{ | |||
while(1) | |||
{ | |||
printf("사이즈를 입력하세요 : "); | |||
scanf("%d",&size); | |||
if(size>2 && size<12) | |||
break; | |||
printf("3에서 11사이만\n"); | |||
} | |||
num=size*size; | |||
k=0; | |||
temp=size; | |||
i=1; | |||
j=size+1; | |||
while(1) | |||
{ | |||
for(k=0;k<size;k++) | |||
{ | |||
j=j+move; | |||
array[i][j]=num; | |||
num--; | |||
} | |||
size--; | |||
move=-move; | |||
for(k=0;k<size;k++) | |||
{ | |||
i=i+move; | |||
array[i][j]=num; | |||
num--; | |||
} | |||
if(size==0) | |||
break; | |||
} | |||
show(); | |||
} | |||
void show() | |||
{ | |||
for(m=1;m<=temp;m++) | |||
{ | |||
for(l=1;l<=temp;l++) | |||
{ | |||
printf(" %3d",array[m][l]); | |||
} | |||
printf("\n"); | |||
} | |||
} | |||
=== 임기찬 === | |||
#include <stdio.h> | |||
void draw(int n, int arr[][11]); //arr 배열에 n x n 달팽이 모양 입력하는 함수 | |||
void print(int n, int arr[][11]); //arr 배열 출력하는 함수 | |||
int main(){ | |||
int n; //n : 입력받는 숫자 | |||
int z = 0; //z : 입력받을때 예외 처리 위해 | |||
int arr[11][11] = { { 0, }, }; // 11 x 11 배열 생성 | |||
while (z == 0){ | |||
printf("n(3~11) : "); | |||
z = scanf("%d", &n); | |||
if (z == 0 || n > 11 || n < 3) { | |||
printf("잘못입력하셨습니다. \n"); | |||
fflush(stdin); | |||
z = 0; | |||
} | |||
} | |||
draw(n, arr); //arr 배열에 n x n 달팽이 모양 입력 | |||
print(n, arr); //arr 배열 출력 | |||
return 0; | |||
} | |||
void draw(int n, int arr[][11]){ //arr 배열에 n x n 달팽이 모양 입력하는 함수 | |||
int i = 0, j = 0, num = 1, k = 0; //i = 행, j = 열, num = 입력할 숫자 | |||
for (; num <= n * n; k++) { | |||
for (; j < n - k; j++, num++) { | |||
arr[i][j] = num; | |||
} | |||
for (i++, j--; i < n - k; i++, num++) { | |||
arr[i][j] = num; | |||
} | |||
for (i--, j--; j >= k; j--, num++) { | |||
arr[i][j] = num; | |||
} | |||
for (i--, j++; i > k; i--, num++) { | |||
arr[i][j] = num; | |||
} | |||
i++, j++; | |||
} | |||
return; | |||
} | |||
void print(int n, int arr[][11]){ //arr 배열 출력하는 함수 | |||
int i, j; //i = 행, j = 열 | |||
for (i = 0; i < n; i++){ | |||
for (j = 0; j < n; j++){ | |||
printf("%3d ", arr[i][j]); | |||
} | |||
printf("\n"); | |||
} | |||
return; | |||
} | |||
=== 홍성현 === | |||
#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--; | |||
} | |||
} | |||
---- | ---- | ||
[[새싹교실/2014]] [[새싹교실/2014/배반]] | [[새싹교실/2014]] [[새싹교실/2014/배반]] | ||
Latest revision as of 00:45, 27 March 2026
개요
내용
- 포인터 --오세상에올것이왔어--
- 망했다고 합니다. 이해하기 너무 힘든 듯.
- 하지만 이번 주가 끝이 아니라고 합니다.후후후후후후후
과제
캡처.PNG Problem? --이 과제를 김승태교수님에게 바칩니다--
- 단, 3~9 말고 3~11
- 이거 하고
- 할 수 있으면 배열을 통한 접근과 포인터를 이용한 접근 둘 다 해볼 것
- 그리고 정수 대신에 주소값을 출력하는 것도 해볼 것
- 이를 통해 주소값이 어떻게 배치되어 있는 지를 알 수 있음
- 달팽이를 출력하는 부분은 꼭 함수로 만들 것.
제출 내용
최필립
- --아는 다른학교 컴공애가 아이디어 제공을 안쓰럽다고 조큼 도와줌--
- 주소값 출력은 그냥 printf 뒤에 &만
- include <stdio.h>
void show();
int i,j;
int num=1,k,move=-1, temp, l,m;
int size;
int array[11][11]={0,};
int main()
{
while(1) { printf("사이즈를 입력하세요 : "); scanf("%d",&size); if(size>2 && size<12) break; printf("3에서 11사이만\n"); }
num=size*size; k=0; temp=size; i=1; j=size+1; while(1) {
for(k=0;k<size;k++) { j=j+move; array[i][j]=num; num--; }
size--;
move=-move;
for(k=0;k<size;k++) { i=i+move; array[i][j]=num; num--; } if(size==0) break; } show();
}
void show() { for(m=1;m<=temp;m++) { for(l=1;l<=temp;l++) {
printf(" %3d",array[m][l]); }
printf("\n"); }
}
임기찬
#include <stdio.h>
void draw(int n, int arr[][11]); //arr 배열에 n x n 달팽이 모양 입력하는 함수
void print(int n, int arr[][11]); //arr 배열 출력하는 함수
int main(){
int n; //n : 입력받는 숫자
int z = 0; //z : 입력받을때 예외 처리 위해
int arr[11][11] = { { 0, }, }; // 11 x 11 배열 생성
while (z == 0){
printf("n(3~11) : ");
z = scanf("%d", &n);
if (z == 0 || n > 11 || n < 3) {
printf("잘못입력하셨습니다. \n");
fflush(stdin);
z = 0;
}
}
draw(n, arr); //arr 배열에 n x n 달팽이 모양 입력
print(n, arr); //arr 배열 출력
return 0;
}
void draw(int n, int arr[][11]){ //arr 배열에 n x n 달팽이 모양 입력하는 함수
int i = 0, j = 0, num = 1, k = 0; //i = 행, j = 열, num = 입력할 숫자
for (; num <= n * n; k++) {
for (; j < n - k; j++, num++) {
arr[i][j] = num;
}
for (i++, j--; i < n - k; i++, num++) {
arr[i][j] = num;
}
for (i--, j--; j >= k; j--, num++) {
arr[i][j] = num;
}
for (i--, j++; i > k; i--, num++) {
arr[i][j] = num;
}
i++, j++;
}
return;
}
void print(int n, int arr[][11]){ //arr 배열 출력하는 함수
int i, j; //i = 행, j = 열
for (i = 0; i < n; i++){
for (j = 0; j < n; j++){
printf("%3d ", arr[i][j]);
}
printf("\n");
}
return;
}
홍성현
- 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--; } }