int yi(int n, char one, char two, char three)
{
if (n == 1)
{
printf("Move from %c to %c !\n",one,three);
}
else
{
yi(n - 1, one, three, two);
printf("Move from %c to %c !\n",one,three);
yi(n- 1, two, one, three);
}
}
int main()
{
int n = 0;
scanf("%d", &n);
yi(n, 'A', 'B', 'C');
return 0;
}
关于#c语言#的问题:汉诺塔问题我想把输出格式改为:第%d次移动:Movefrom%cto%c
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- threenewbee 2023-05-02 12:46关注
int count; int yi(int n, char one, char two, char three) { if (n == 1) { printf("第%d次移动, Move from %c to %c !\n",++count, one,three); } else { yi(n - 1, one, three, two); printf("第%d次移动, Move from %c to %c !\n",++count,one,three); yi(n- 1, two, one, three); } } int main() { int n = 0; count = 0; scanf("%d", &n); yi(n, 'A', 'B', 'C'); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 io.jsonwebtoken.security.Keys
- ¥15 急,ubuntu安装后no caching mode page found等
- ¥15 联想交换机NE2580O/NE1064TO安装SONIC
- ¥15 防火墙的混合模式配置
- ¥15 Ubuntu不小心注销了要怎么恢复啊
- ¥15 win10电脑安装完plcsim advanced4.0运行时为什么会提示找不到虚拟网卡
- ¥15 安装powerbuilder10卡在安装程序正在运行这个页面 没有下一步任何指令
- ¥15 关于mpi的问题:请问遇到这种情况需要怎么解决,出现这个问题后电脑不能进行mpi多核运行只能进行单核运行
- ¥50 微信聊天记录备份到电脑提示成功了,但还是没同步到电脑微信
- ¥15 python怎么在已有视频文件后添加新帧