解题思路:
注意事项:
参考代码:
#include<stdio.h>
int main()
{
void hanoi(int n,char x,char y,char z);
int m;
//printf("input the number of dishes:");
scanf("%d",&m);
//printf("The step to moving %d dishes:\n",m);
hanoi(m,'1','2','3');
return 0;
}
void hanoi(int n,char x,char y,char z)
{
void move(int n,char a,char b);
if(n==1)
move(n,x,z);
else
{
hanoi(n-1,x,z,y);
move(n,x,z);
hanoi(n-1,y,x,z);
}
}
void move(int n,char a,char b)
{
printf("Move %d from %c to %c\n",n,a,b);
}
0.0分
1 人评分
【蟠桃记】 (C语言代码)浏览:651 |
WU-C语言程序设计教程(第三版)课后习题11.11 (C++代码)(想学链表的可以看看)浏览:1358 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:633 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:577 |
IP判断 (C语言代码)浏览:539 |
简单的a+b (C语言代码)浏览:830 |
数列排序 (C语言代码)浏览:616 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:532 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:722 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:555 |