递归求汉诺塔的解
#include "stdafx.h"
#include<stdio.h>
#include<conio.h>
#include<windows.h>
void HanoiTower(int,char,char,char);
void main()
{
int n;
char A='A',B='B',C='C';
printf("---Hanoi Tower Implementation---\n");
printf("How many disks in A ?\n");
scanf("%d",&n);
if(n==0)
printf("no disks to move\n");
else
HanoiTower(n,A,B,C);
system("pause");
}
void HanoiTower(int n,char a,char b,char c)
{
if(n==1)
printf("Move disk 1 from %c->%c\n",a,c);
else
{
HanoiTower(n-1,a,c,b);
printf("Move disk %d from %c->%c\n",n,a,c);
HanoiTower(n-1,b,a,c);
}
}