c语言-汉诺塔递归调用

#include

 

int l=0;

 

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');

    

    printf("总数为=%d",l);

 

    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)

 

{

   l++;

 

 

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

 

}

转载于:https://www.cnblogs.com/mathstudysharing/p/10283324.html

你可能感兴趣的:(c/c++)