#include <stdio.h>


void hanoi(int n, char from, char to, char temp);
double count = 0;

int main(int argc, char* argv[])
{
int num;

printf("옮길 원판의 갯수를 입력하시오 (1~64) : ");
scanf("%d", &num);

hanoi(num, 'A', 'C', 'B');
printf("원판의 갯수는 %d개 이고, 옮긴 횟수는 %g번 입니다. \n", num, count);
 return 0;
}


void hanoi(int n, char from, char to, char temp)
{
 count++;

 if ( n == 1 ) {

  printf("원판 1 을 %c 에서 %c 로 이동합니다. \n", from, to);
  }
 else {
  hanoi(n-1, from, temp, to);
  printf("원판 %d 을 %c 에서 %c 로 이동합니다. \n", n, from, to);
  hanoi(n-1, temp, to, from);
 }
}
// 그 유명한 하노이의 탑이죠...
// C를 공부한 학생이라면 발로 짤 수 있는 소스입니다.

Posted by 정훈승