Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dest' instead of 'src' for the source peg.
Using an undefined variable like 'disk'.
✗ Incorrect
The source peg is represented by 'src', so we print the move from src to dest.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'src' or peg names instead of the number of disks.
Using n instead of n-1.
✗ Incorrect
We move n-1 disks, so the argument should be n-1.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking peg names instead of the number of disks.
Using 'n == 0' which never triggers the move.
✗ Incorrect
The base case checks if n equals 1 to stop recursion.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping source and temporary pegs incorrectly.
Using n instead of n-1.
✗ Incorrect
We move n-1 disks from temp to dest using src as auxiliary.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'disk' as a parameter name.
Mixing peg names or missing the number of disks parameter.
✗ Incorrect
The function takes number of disks n, source peg src, temporary peg temp, and destination peg dest.