hanoi塔 功能:编程序显示n(n<=9)层汉诺威塔的调整过程

来源:百度知道 编辑:UC知道 时间:2024/06/15 20:01:25
实现5层汉诺威塔的调整过程;进一步要求:直至实现n=9时的情况,程序要加必要的注释
1. 要有数据结构,界面友好,函数功能要划分好

2.总体设计应画一流程图

3.程序要加必要的注释

4.要提供程序测试方案

5.程序一定要经得起测试,宁可功能少一些,也要能运行起来,不能运行的程序是没有价值的。

#include "stdio.h"
void move(char x,char y)
{ printf("%c-->%c\n",x,y);
}
void hanoi(int n,char one,char tow,char three)
{ if(n==1)
move(one,three);
else
{ hanoi(n-1,one,three,tow);
move(one,three);
hanoi(n-1,tow,one,three);
}
}
void main()
{ int m;
printf("input the number of diskes:");//输入层数
scanf("%d",&m);
printf("the step to moving %d diskes:\n",m);
hanoi(m,'A','B','C');
}