01河内之塔

参考链接

https://www.cnblogs.com/xt0810/p/3442840.html
#include 
#include 

int Hanoi(int n,char A, char B, char C) {
    if (n == 1) {
        printf("Move sheet %d from %c to %c\n",n,A,C);
    } else {
        Hanoi(n-1,A,C,B);
        printf("Move sheet %d from %c to %c\n",n,A,C);
        Hanoi(n-1,B,A,C);
    }
    return 0;
}
int main() {
    int n;
    printf("请输入盘子个数:");
    scanf("%d",&n);
    Hanoi(n,'A','B','C');
    printf("Hello world!\n");
    return 0;
}

 

转载于:https://www.cnblogs.com/yaozhenhua/p/10989317.html

你可能感兴趣的:(01河内之塔)