解题思路:
注意事项:
参考代码:
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<malloc.h> #include<math.h> int i=1; void move(int n,char from,char to){ printf("%2d. Move disk %d from %c to %c\n",i++,n,from,to); } void hanoi(int n,char from,char dep,char to){ if(n==1){ move(1,from,to); } else{ hanoi(n-1,from,to,dep); move(n,from,to); hanoi(n-1,dep,from,to); } } int main(){ int num; while(scanf("%d",&num)==1){ char a='X',b='Y',c='Z'; hanoi(num,a,b,c); printf("\n"); i=1; } return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:605 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:655 |
C语言程序设计教程(第三版)课后习题1.5 (C++代码)浏览:759 |
字符串比较 (C语言代码)答案错误????浏览:597 |
printf基础练习2 (有点不明白)浏览:845 |
【金明的预算方案】 (C++代码)浏览:843 |
WU-C语言程序设计教程(第三版)课后习题12.1 (C++代码)浏览:941 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:550 |
求圆的面积 (C语言代码)浏览:1670 |
C语言训练-自由落体问题 (C语言代码)浏览:620 |