汉诺塔程序

/*description: hanio   
author: jz    
Date: 20140818*/
#include<stdio.h>
int count=0;
void move(int n,char t1,char t2)
{
	printf("%3d:%d  %c-->%c\n",++count,n,t1,t2);//第几部  编号多少的盘子 从X移到X
}
void hanoi(int n,char a,char b,char c)
{
	if (n<=0)
	{
		printf("error! need't move\n");
	}
	else	if (1==n)
	{
		move(n,a,c);
	}
	else
	{
		hanoi(n-1,a,c,b);
		move(n,a,c);
		hanoi(n-1,b,a,c);
	}
}

void main()
{
	int n;
	printf("Please input hanoi number:");
	scanf("%d",&n);
	//char a='a',b,c;
	hanoi(n,'a','b','c');
}

你可能感兴趣的:(汉诺塔程序)