代码如下:
#include<stdio.h>
void hanoi (int n,int a,int b,int c)
{
if(n==1)
{
printf("\n第几%d次,%c柱-->%c柱\n",n,a,c);
}
else
{
hanoi(n-1,a,c,b);
printf("\n第几%d次,%c柱-->%c柱\n",n,a,c);
hanoi(n-1,b,a,c);
}
}
int main()
{
int n;
printf("请输入要A柱汉诺塔圆盘的个数:");
scanf("%d",&n);
hanoi(n,'A','B','C');
getch();
return 0;
}