Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Let us assume that the priests are attempting tomove the disks from peg 1 to peg

ID: 3618056 • Letter: L

Question

Let us assume that the priests are attempting tomove the disks from peg 1 to peg 3. We wish to develop an algorithmthat prints the precise sequence of peg-to-peg disk transfers.

If we were to approach this problem withconventional methods, we would rapidly find ourselves hopelesslyknotted up in managing the disks. Instead, attacking this problemwith recursion in mind allows the steps to be simple. Moving ndisks can be viewed in terms of moving only n1 disks (hence, therecursion), as follows:

Move n 1 disks from peg 1 to peg 2, using peg 3as a temporary holding area.

Move the last disk (the largest) from peg 1 topeg 3.

Move the n 1 disks from peg 2 to peg 3, usingpeg 1 as a temporary holding area.

Explanation / Answer

please rate - thanks #include #include void hanoi(int n, int from, int to , int use); main() {int n; printf("How many disks do you have? "); scanf("%d",&n); printf("move: "); printf("from to "); printf(" peg peg "); hanoi(n,1,2,3); getch(); return 0; } void hanoi(int n, int from, int to , int use) {      if(n==1)         printf("%d      %d ",from,to);      else      {         hanoi(n-1,from,use,to);         hanoi(1,from,to,use);         hanoi(n-1,use,to,from);      } }