728x90
#include <stdio.h>
void pause()
{
int x;
fprintf(stderr, "종료하려면 아무키나 누르세요");
getch();
}
void hanoi_tower(int n, char from, char tmp, char to)
{
if (n == 1)
printf("원판 1을 %c 에서 %c으로 옮긴다.\n", from, to);
else
{
hanoi_tower(n - 1, from, to, tmp);
printf("원판 %d을 %c에서 %c으로 옮긴다.\n", n, from, to);
hanoi_tower(n - 1, tmp, from, to);
}
}
int main(void)
{
hanoi_tower(4, 'A', 'B', 'C');
pause();
}
728x90
'언어 > C' 카테고리의 다른 글
| [C] 재귀 함수와 for문으로 피보나치수열 찾기 (0) | 2023.04.19 |
|---|---|
| [C] strlen, strcmp, strcpy, strcat (0) | 2023.04.06 |
| [C] 피보나치 수열 구하기 (0) | 2023.04.05 |
| [C] 구구단 + 합 구하기 (0) | 2023.03.16 |
| [C] 소수 구하기, 소수의 합 구하기 (0) | 2023.03.16 |