学习C/C++语言:递归求解hanoi汉诺塔问题

#include
void hanoi(int n,char one,char two,char three);
void move(char a,char b);
void main()
{
	int n;
	printf("input the number of diskes:\n");
	scanf("%d",&n);
	printf("the step to moving %d diskes:\n",n);
	hanoi(n,'A','B','C');
}
void move(char a,char b)
{
	printf("%c-->%c\n",a,b);
}
void hanoi(int n,char one,char two,char three)
{
	if(n==1)
		move(one,three);
	else
	{
		hanoi(n-1,one,three,two);
		move(one,three);
		hanoi(n-1,two,one,three);
	}
}

你可能感兴趣的:(C/C++)