###### tags: `I2P(I)Hu2023` # 12486 - Tower of Hanoi > by schdoel ## Brief Complete the tower of hanoi puzzle ## Solution Complete recursion by first moving the n-1 disks on top of the bottommost disk to B, then moving the bottommost disk to C, and finally moving the n-1 disks back to C. ## Reference Code ```cpp= #include <stdio.h> void hanoi(int n, char A, char B, char C){ if(n==1){ //Basis Step printf("move disk 1 from rod %c to rod %c\n", A, C); } else{ //Inductive Step hanoi(n-1, A, C, B); printf("move disk %d from rod %c to rod %c\n", n, A, C); hanoi(n-1, B, A, C); } } int main(){ int n; scanf("%d", &n); hanoi(n, 'A', 'B', 'C'); return 0; } ```