Question: Using SPIM, write and test a recursive program for solving the classic mathematical recreation, the Towers of Hanoi puzzle. The puzzle consists of three pegs

Using SPIM, write and test a recursive program for solving the classic mathematical recreation, the Towers of Hanoi puzzle. The puzzle consists of three pegs (1,2, and 3) and n disks (the number n can vary; typical values might be in the range from 1 toDisk 1 is smaller than disk 2, which is in turn smaller than disk 3, and so forth, with disk n being the largest. Initially, all the disks are on peg 1, starting with disk n on the bottom, disk n 1 on top of that, and so forth, up to disk 1 on the top. The goal is to move all the disks to peg 2. You may only move one disk at a time, that is, the top disk from any of the three pegs onto the top of either of the other two pegs. Moreover, there is a constraint: You must not place a larger disk on top of a smaller disk.
make this based on the following program
#include
using namespace std;
void hanoi(int n, char from, char to , char use);
main()
{int n;
cout<<"How many disks do you have? ";
cin>>n;
cout<<"move:
";
cout<<"from to
";
cout<<" peg peg
";
hanoi(n,'O','D','S');
system("pause");
return 0;
}
void hanoi(int n, char from, char to ,char use)
{
if(n==1)
cout<<""<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!