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

Use any programming language you know of, to implement the Hanoi Tower. You must

ID: 3567434 • Letter: U

Question

Use any programming language you know of, to implement the Hanoi Tower. You must make the program to output the solution for 6 disks, showing how a disk is moved from a tower to another for every move. Your solution should look like the following, when the number of disks is 3:

OUTPUT SHOULD BE

[T1] 3 2 1
[T2]
[T3]
move disk 1 from [T1] to [T3]
[T1] 3 2
[T2]
[T3] 1
move disk 2 from [T1] to [T2]
[T1] 3
[T2] 2
[T3] 1
move disk 1 from [T3] to [T2]
[T1] 3
[T2] 2 1
[T3]
move disk 3 from [T1] to [T3]
[T1]
[T2] 2 1
[T3] 3
move disk 1 from [T2] to [T1]
[T1] 1
[T2] 2
[T3] 3
move disk 2 from [T2] to [T3]
[T1] 1
[T2]
[T3] 3 2
move disk 1 from [T1] to [T3]
[T1]
[T2]
[T3] 3 2 1

Explanation / Answer

#include main() { int n, a[50], key, opn, i, pos; do { clrscr(); printf( " Press 1 -> Binary Search , 2-> Towers of Hanoi 3-> Quit "); scanf("%d", &opn); switch (opn) { case 1: printf(" How Many Elements?"); scanf("%d", &n); printf(" Read all the elements is ASC order "); for (i = 1; i high) return 0; /* failure */ else { mid = (low + high) / 2; if (a[mid] == key) return mid; /* Success */ if (key 0) { tower(n - 1, src, dst, intr); printf("Move disk %d from %c to %c ", n, src, dst); tower(n - 1, intr, src, dst); } }