汉诺塔

#include<stdio.h>

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

void hanoi(int n,char one,char two,char three)
{
    if(n==1) move(one,three);
    else
    {
        hanoi(n-1,one,three,two);
        move(one,three);
        hanoi(n-1,two,one,three);
    }
}

void main()
{
    int n;
    printf("input the number of diskes: ");
    scanf("%d",&n);
    printf("the steps of moving %d diskes :\n",n);
    hanoi(n,'A','B','C');
}

你可能感兴趣的:(汉诺塔)