Write a C program to verify that a given sequence of moves will translate the st
ID: 3621144 • Letter: W
Question
Write a C program to verify that a given sequence of moves will translate the starting position to the solution position for the Tower of Hanoi Game.
The moves are given like move(disk,tower) each move must be checked to see that it doesn't violate the rules (i.e. a larger disk cannot be placed on a smaller one) and then the solution must be checked to make sure it is on a different tower than it started.
we are to enter the moves and then check them so the moves for a 3 tower 3 disk game where disk 1 is the smallest and 3 is the largest and tower 1 is left most and tower 3 right most is
move(1,3)
move(2,2)
move(1,2)
move(3,3)
move(1,1)
move(2,3)
move(1,3)
please help i dont know where to even start
Explanation / Answer
#include void towersOfHanoi(int, char, char, char); int main() { int n; printf("Towers of Hanoi "); printf(" Enter the number of disks : "); scanf("%d", &n); towersOfHanoi(n,'1','2','3'); system("pause"); } void towersOfHanoi(int n, char peg1, char peg2, char peg3) { if (n != 0) { towersOfHa... #include void towersOfHanoi(int, char, char, char); int main() { int n; printf("Towers of Hanoi "); printf(" Enter the number of disks : "); scanf("%d", &n); towersOfHanoi(n,'1','2','3'); system("pause"); } void towersOfHanoi(int n, char peg1, char peg2, char peg3) { if (n != 0) { towersOfHanoi(n-1, peg1, peg3, peg2); printf(" Move of disk %d ", n ); printf(" is %c", peg1); printf(" -> "); printf("%c ", peg3);; towersOfHanoi(n-1, peg2, peg1, peg3); } } I hope this will helps to You !Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.