Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void move(int n,char x,char y,char z)
- {
- if(1==n)
- {
- printf("%c-->%c\n",x,z);
- }
- else
- {
- move(n-1,x,z,y);
- printf("%c-->%c\n",x,z);
- move(n-1,y,x,z);
- }
- }
- int main()
- {
- int n;
- printf("请输入汉罗塔的层数:");
- scanf("%d",&n);
- printf("移动的步骤如下: \n");
- move(n,'x','y','z');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement