汉诺塔问题

/**
 *汉诺塔问题
*/
#include <stdio.h>
#include <stdlib.h>

int main(int argc,char *argv[]){
        
    void hanoi(int n,char one,char two,char three);
    int n;
    printf("Please input the number of diskes:");
    scanf("%d",&n);
    printf("The step to moving %d diskes:\n",n);
    hanoi(n,'A','B','C');
}

//将n个盘子从one座借助two座,移到three座
void hanoi(int n,char one,char two,char three){
        
    void move(char x,char y); 
    if(n == 1)
        move(one,three);
    else{
        hanoi(n-1,one,three,two);
        move(one,three);
        hanoi(n-1,two,one,three);
    }   
}

void move(char x,char y){ 
    printf("%c——>%c\n",x,y);
}  

你可能感兴趣的:(C++,c,C#)