Hanoi汉诺塔递归
#include<stdio.h>
void hanoi(int n,char x,char y,char z);
int main()
{ char x;
char y;
char z;
hanoi(3,'x','y','z');
}
void hanoi(int n,char x,char y,char z)
{
if(n==1)
{
printf("将第%d个盘片移动到%c\n",n,x,z);
}
else{
hanoi(n-1,x,z,y);
printf("将第%d个盘片从%c移动到%c\n",n,x,y);
hanoi(n-1,y,x,z);
}
}