#include <stdio.h>
int step = 0;
void hanoi(int n, char start, char assist, char end){
if(n>=1){
hanoi(n-1, start, end, assist);
printf("move %d from %c --> %c \n", n, start, end);
step++;
hanoi(n-1, assist, start, end);
}
}
int main(){
int n;
scanf("%d", &n);
hanoi(n, ‘A‘, ‘B‘, ‘C‘);
printf("Totally move %d steps\n", step);
return 0;
}
Please input the disk num:
3
move 1 from A --> C
move 2 from A --> B
move 1 from C --> B
move 3 from A --> C
move 1 from B --> A
move 2 from B --> C
move 1 from A --> C
Totally move 7 steps