c语言-汉诺塔递归调用

#include<stdio.h>

int main()

{

    void hano_tower(int n,char one,char two,char three);

    int m=0;

    printf("Please enter a number:\n");

    scanf("%d",&m);

    printf("You need move like this:\n");

    hano_tower(m,'A','B','C');

    return 0;

}

void hano_tower(int n,char one,char two,char three)

{

    void move(char x,char y);

    if(n==1)

    move(one,three);

    else

    {

    hano_tower(n-1,one,three,two);

    move(one,three);

    hano_tower(n-1,two,one,three);

    }

}

void move(char x,char y)

{

   printf("%c->%c\n",x,y);

}

猜你喜欢

转载自www.cnblogs.com/mathstudysharing/p/10283324.html