//Towers of Hanoi
# include <iostream>
using namespace std;
void hanoi(int , int , int, int);
int main ()
{
int numdiscs;
cout << "Please enter the number
of discs\n";
cin >> numdiscs;
//Initial peg is 1, final peg is 3.
hanoi(numdiscs, 1, 3, 2);
return 0;
}
void hanoi(int num, int start, int end, int temp)
{
//base case
if(num==1)
{
cout
<< "Move from peg " << start;
cout << " to peg "
<<
end << "\n";
return;
}
else
{
// move num-1 discs from start to
temp
// recursive call
hanoi(num-1, start, temp, end);
//move last disc from start to end
cout << "Move from peg "
<< start;
cout << " to peg "
<< end << "\n";
//move num-1 discs from end to
temp
//recursive call
hanoi(num-1,temp, end, start);
}
}