递归汉诺塔问题

#include <stdio.h>
int main()
{
	void hanoi(int n,char A,char B,char C);
	hanoi(3,'A','B','C');
	return 0;
}

void hanoi(int n,char A,char B,char C)
{
	if(n==1)
	{
		printf("%c -> %c\n",A,C);
	}else{
		hanoi(n-1,A,C,B);
		printf("%c -> %c\n",A,C);
		hanoi(n-1,B,A,C);
	}
	
}

  

posted @ 2020-03-24 19:25  Arielsixsixsix  阅读(86)  评论(0编辑  收藏  举报