汉罗塔问题,递归,C语言,经典

img

#include<stdio.h>
int step;
void hanoi(int n,char a,char b,char c){
    if(n==1){
        step++;
        printf("[step %d] move plate %d# from %c to %c\n",step,1,a,c);
    }else{
        hanoi(n-1,a,c,b);
        step++;
        printf("[step %d] move plate %d# from %c to %c\n",step,n,a,c);
        hanoi(n-1,b,a,c);
    }
}
int main() {
    int n;
    scanf("%d",&n);
    hanoi(n,'a','b','c');
    printf("%d",step);
    return 0;
}