[C算法]递归方式求"汉诺塔"

#include <stdio.h>

void hanoi(int n, char one, char two, char three)
{
if(n==1)
{
printf("%c--------->%c\n",one,three);
}
else if(n<0||n==0)
{
return;
}
else
{
hanoi(n-1, one, three, two);
printf("%c--------->%c\n", one, three);
hanoi(n-1, two, one, three);
}
}

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

你可能感兴趣的:(算法)