~cpp
#include <iostream>
using namespace std;
int Mcount = 0; //ì�´ë�™íšŸìˆ˜ì„¸ê¸° 위한 ì „ì—변수
int hanoi(int disk,int start, int other, int finish){
Mcount++; //함수가 호출ë� 때 마다 1씩 ì¦�ê°€
// 마지막�거나 디스�가 1�때 start 기둥 �서 finish 기둥 으로 옮김
if(disk == 1)
cout << start << "�서 " << finish << endl;
// 디스�갯수가 1� 아니면서 마지막� 아�때
else
{
hanoi(disk-1,start,finish,other); // ��반� 뺀 위� 것들� other 기둥으로 옮기는 재귀함수 호출
cout << start << "�서 " << finish << endl;
hanoi(disk-1,other,start,finish); // other 기둥� 있는 것� finish 기둥으로 옮기는 재귀함수 호출
}
return Mcount;
}
void main(){
int disk,MoveCount;
cout << "디스� 갯수 : ";
cin >> disk;
MoveCount = hanoi(disk,1,2,3);
cout << endl << "최소 ��횟수" << MoveCount << endl;
}