这个代码是根据小甲鱼的那个数据结构与算法码出来的
#include <stdio.h>
void move(int n, char x,char y, char z){
if( 1 == n ){
printf("%c-->%c\n",x,z);
}
else{
move(n-1,x,z,y);
printf("%c-->%c\n",x,z);
move(n-1,y,x,z);
}
}
int main(void)
{
int n;
printf("Please enter the floor number of Hanoi tower:");
scanf("%d",&n);
printf("The steps to move are as follows:\n");
move(n,'X','Y','Z');
return 0;
}
预览结果