<span style="font-size:14px;">#include<stdio.h>
int times = 0; //用于记录移动次数
void hanoi(int n,char A,char B,char C)
{
times += 1;
if(n==1)
{
printf("Move disk %d from %c to %c\n",n,A,C);
}
else
{
hanoi(n-1,A,C,B);
printf("Move disk %d from %c to %c\n",n,A,C);
hanoi(n-1,B,A,C);
}
}
int main()
{
int n;
printf("请输入圆盘个数n\n");
scanf("%d",&n);
hanoi(n,'A','B','C');
printf("总共需要次数为:%d\n",times);
return 0;
}</span>