今天脑子很清醒,所以编了一下汉诺塔,其实早都想写写了,可是课业太多,一直没时间,正好今天是周六可以练习一下了,呵呵...
#include <stdio.h>
int count=0;
void hanoi(int n, char from, char to, char middle)
{
if (n > 0)
{
count++;
hanoi(n-1, from, middle, to);
printf("Move No.%-2d from %c to %c/n", n, from, to);
hanoi(n-1, middle, to, from);
}
}
void main()
{
int init ;
printf("please input the numble:");/*输入盘子的数量*/
scanf("%d",&init);
printf("A 是起始杆,C 是辅助杆,B 是目的杆。/n/n");
hanoi(init, 'A', 'C' , 'B');
printf("/nCount = %d", count);
}