test
코드좀 알 수 있을까요??ㅠㅠㅠ
원반이 하나씩 움직여야 할것 같은데요. 왜 다들. 재귀 호출 함수'로 횟수만 맞춰놨는지 모르겠네요. 이거로 확인하니. 이동한 원반번호'의 순서와 출력결과의 첫자리'가 일치했습니다. codepad.org/ganabVRw 스크랫치 프로그램도 있네요. (메뉴에서 터보모드'로 하시면. 더 빠릅니다.) scratch.mit.edu/projects/28738/#editor #include <stdio.h> #include <stdlib.h>void hanoi( int n, int a, int b, int c ) { if ( n > 0 ) // STOP 조 { hanoi( n-1, a, c, b ); // printf(" Move disk from %d to %d. ", a, b); // 실제 disk를 이동하는 부분 printf("%d %d %d %d ", n, a, b, c); hanoi( n-1, c, b, a ); } else { return; } } int main(void) { int n; //원반 갯수 int a = 0, b = 1, c = 2; //기둥 printf("<hanoi> input number of disk: "); // scanf("%d", &n); n = 4; hanoi( n, a, b, c ); return 0; }1 0 2 1 2 0 1 2 1 2 1 0 3 0 2 1 1 1 0 2 2 1 2 0 1 0 2 1 4 0 1 2 1 2 1 0 2 2 0 1 1 1 0 2 3 2 1 0 1 0 2 1 2 0 1 2 1 2 1 0
test
test
코드좀 알 수 있을까요??ㅠㅠㅠ
원반이 하나씩 움직여야 할것 같은데요. 왜 다들. 재귀 호출 함수'로 횟수만 맞춰놨는지 모르겠네요. 이거로 확인하니. 이동한 원반번호'의 순서와 출력결과의 첫자리'가 일치했습니다. codepad.org/ganabVRw 스크랫치 프로그램도 있네요. (메뉴에서 터보모드'로 하시면. 더 빠릅니다.) scratch.mit.edu/projects/28738/#editor #include <stdio.h> #include <stdlib.h>void hanoi( int n, int a, int b, int c ) { if ( n > 0 ) // STOP 조 { hanoi( n-1, a, c, b ); // printf(" Move disk from %d to %d. ", a, b); // 실제 disk를 이동하는 부분 printf("%d %d %d %d ", n, a, b, c); hanoi( n-1, c, b, a ); } else { return; } } int main(void) { int n; //원반 갯수 int a = 0, b = 1, c = 2; //기둥 printf("<hanoi> input number of disk: "); // scanf("%d", &n); n = 4; hanoi( n, a, b, c ); return 0; }1 0 2 1 2 0 1 2 1 2 1 0 3 0 2 1 1 1 0 2 2 1 2 0 1 0 2 1 4 0 1 2 1 2 1 0 2 2 0 1 1 1 0 2 3 2 1 0 1 0 2 1 2 0 1 2 1 2 1 0