解题思路:
注意事项:
参考代码:
#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++代码)浏览:1110 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:424 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:748 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:1222 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:654 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:703 |
三角形 (C语言代码)浏览:903 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:1909 |
图形输出 (C语言代码)浏览:1375 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:398 |