Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. #include<stdio.h>
  2. void move(int n,char x,char y,char z)
  3. {
  4. if(1==n)
  5. {
  6. printf("%c-->%c\n",x,z);
  7. }
  8. else
  9. {
  10. move(n-1,x,z,y);
  11. printf("%c-->%c\n",x,z);
  12. move(n-1,y,x,z);
  13. }
  14. }
  15. int main()
  16. {
  17. int n;
  18.  
  19. printf("请输入汉罗塔的层数:");
  20. scanf("%d",&n);
  21. printf("移动的步骤如下: \n");
  22. move(n,'x','y','z');
  23.  
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement