64,660
社区成员
发帖
与我相关
我的任务
分享
void hanoi1(int n,char here,char there) // 把n盘从here移到there
{
printf("move %d from %c to %c\n",n,here,there);
}
void hanoi2(char here,char temp,char there)
{
hanoi1(1,here,temp);
hanoi1(2,here,there);
hanoi1(1,temp,there);
}
void hanoi3(char here,char temp,char there)
{
hanoi2(here,there,temp);
hanoi1(3,here,there);
hanoi2(temp,here,there);
}
int main()
{
hanoi3('A','B','C'); // 从A柱移到C柱
return 0;
}
int fact(int n)
{
static int mark=0;
printf("times:%d, n:%d\n",mark,n);
++mark;
if(n>1)
{
int ans=n*fact(n-1);
printf("times:%d, ans:%d\n",mark,ans);
return ans;
}
else
{
int ans=1;
printf("times:%d, ans:%d\n",mark,ans);
return ans;
}
}
int main()
{
int ans=fact(3);
return 0;
}