0
0
DSA Cprogramming~10 mins

Tower of Hanoi Problem in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print the move from source to destination.

DSA C
printf("Move disk from %c to %c\n", [1], dest);
Drag options to blanks, or click blank then click option'
Adest
Bdisk
Ctemp
Dsrc
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dest' instead of 'src' for the source peg.
Using an undefined variable like 'disk'.
2fill in blank
medium

Complete the code to move n-1 disks from source to temporary peg.

DSA C
towerOfHanoi([1] - 1, src, temp, dest);
Drag options to blanks, or click blank then click option'
An
Bsrc
Ctemp
Ddest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'src' or peg names instead of the number of disks.
Using n instead of n-1.
3fill in blank
hard

Fix the error in the base case condition to stop recursion.

DSA C
if ([1] == 1) {
Drag options to blanks, or click blank then click option'
An
Bsrc
Ctemp
Ddest
Attempts:
3 left
💡 Hint
Common Mistakes
Checking peg names instead of the number of disks.
Using 'n == 0' which never triggers the move.
4fill in blank
hard

Fill both blanks to move n-1 disks from temporary to destination peg.

DSA C
towerOfHanoi([1] - 1, [2], src, dest);
Drag options to blanks, or click blank then click option'
An
Btemp
Csrc
Ddest
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping source and temporary pegs incorrectly.
Using n instead of n-1.
5fill in blank
hard

Fill all three blanks to complete the recursive Tower of Hanoi function signature.

DSA C
void towerOfHanoi(int [1], char [2], char [3], char dest) {
Drag options to blanks, or click blank then click option'
An
Bsrc
Ctemp
Ddisk
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'disk' as a parameter name.
Mixing peg names or missing the number of disks parameter.