主题:汉诺塔递归添加一个纪录步骤的变量
如题,我想添加个纪录转移步骤的变量step,不知道加到什么地方,试了几遍都错了,麻烦大伙帮改下,谢谢哦。
#include <stdio.h>
void hannuota(int n,char A,char B,char C)
{
int step=0;//用于记录操作步骤数。
if(1==n)
{
step=1;
printf("第%d步,直接将第%d个盘子从%c移到%c\n",step,n,A,C);
}
else
{
hannuota(n-1,A,C,B);
printf("第%d步,直接将第%d个盘子从%c移到%c\n",step,n,A,C);
hannuota(n-1,B,A,C);
}
}
int main(void)
{
int n;
char a='A',b='B',c='C';
printf("how many disk you want to move:\n");
scanf("%d,",&n);
hannuota(n,'A','B','C');
return 0;
}
#include <stdio.h>
void hannuota(int n,char A,char B,char C)
{
int step=0;//用于记录操作步骤数。
if(1==n)
{
step=1;
printf("第%d步,直接将第%d个盘子从%c移到%c\n",step,n,A,C);
}
else
{
hannuota(n-1,A,C,B);
printf("第%d步,直接将第%d个盘子从%c移到%c\n",step,n,A,C);
hannuota(n-1,B,A,C);
}
}
int main(void)
{
int n;
char a='A',b='B',c='C';
printf("how many disk you want to move:\n");
scanf("%d,",&n);
hannuota(n,'A','B','C');
return 0;
}