C语言实现汉诺塔问题

代码如下:

#include <stdio.h>
#include <stdlib.h>
void move(int n,char x,char y,char z) {
    if (n==1) {
        printf("%c--->%c
",x,z);
    }else {
        move(n-1,x,z,y);
        printf("%c--->%c
",x,z);
        move(n-1,y,x,z);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    move(n,'X','Y','Z');
    return 0;
}
原文地址:https://www.cnblogs.com/ncuhwxiong/p/7092199.html