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

Need help with homework assignement. This is C language. Correct answer will get

ID: 3805929 • Letter: N

Question

Need help with homework assignement. This is C language. Correct answer will get a thumbs up!

1. Consider the Hanoi tower program again. We discussed how to write a function to solve the Hanoi tower problem in an earlier class. Hanoi tower problem: there are three poles labeled by 1, 2, 3. There are n discs of different sizes on pole I. Each disc s sitting on a disc with a bigger size. The discs on pole I are labeled from 1 to n from top to bottom. Print a sequence ofmoves such that a. every move can move only one disc (from one pole to another) b. no disc may be placed on the smaller disc c. one can only move the top most disc ofa pole and put it on the top of any other discs of another pole, and d. after the sequence of moves, all discs will be on pole 3. An execution of a program to solve the problem is as follows: Input the numbe r discs on pole a Move disc 1 from pole 1 t pole 2 o Move disc 2 from pole 1 t pole 3 o Move disc 1 from pole 2 t o pole 3 a. Consider the following pseudocode function Function name: moveDiscs input a, b, c: the three poles n: the number of discs on pole a. output none. side effect: print a sequence of moves such that all m discs on a will be moved to polecusing pole b, when needed, as a temporal pole. Plan fill the plan To write the plan for the function moveDiscs above, s the following problem decomposition a correct one? Why? P1: move the first (top most) disc on pole a to pole b, P2: move the rest of the discs on pole a to pole c. P3: move the only disc on pole b to pole c.

Explanation / Answer

HI, Please find my program.

Please let me know in case of any issue.

#include <stdio.h>

// C recursive function to solve tower of hanoi puzzle
void moveDiscs(int n, char fromrod, char torod, char auxrod)
{
if (n == 1)
{
printf("Move disk 1 from rod %c to rod %c ", fromrod, torod);
return;
}
moveDiscs(n-1, fromrod, auxrod, torod);
printf("Move disk %d from pole %c to pole %c ", n, fromrod, torod);
moveDiscs(n-1, auxrod, torod, fromrod);
}

int main()
{
int n = 4; // Number of disks
moveDiscs(n, '1', '2', '3'); // A, B and C are names of rods
return 0;
}