#include
void HN(int n,char a,char b,char c);
int main(int argc,char *argv[])
{
int Dish_num;
printf("Please Input the Dish num: ");
scanf("%d",&Dish_num);
while(Dish_num != 0){
printf("%d个盘子的移动步骤如下:\n",Dish_num);
HN(Dish_num,‘A‘,‘B‘,‘C‘);
printf("Please
Input the Dish num: ");
scanf("%d",&Dish_num);
}
while(1);
return 0;
}
void HN(int m,char a,char b,char c)
{
if(m==1){
printf("From
%c to %c\n",a,c);
}
else{
HN(m-1,a,c,b);
printf("From
%c to %c\n",a,c);
HN(m-1,b,a,c);
}
}
时间: 2024-10-11 14:51:16