如何用Dev C++解决汉诺塔问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 17:17:37

#include <iostream>
using namespace std;
void hanoi(int nPlate,int iFrom,int iBy,int iTo)
{
if (nPlate==1)
cout << iFrom << "->" << iTo << endl;
else
{
hanoi(nPlate-1,iFrom,iTo,iBy);
cout << iFrom << "->" << iTo << endl;
hanoi(nPlate-1,iBy,iFrom,iTo);
}
}

void main()
{
int nPlate;
cout << "Please input the number of the plate:";
cin >> nPlate;
hanoi(nPlate,1,2,3);
}