Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void Hanoi(int n,int s,int a,int d)
- {
- if(n==1)
- printf("Move piece %d from tower %d to tower %d\n",n,s,d);
- else
- {
- Hanoi(n-1,s,d,a);
- printf("Move piece %d from tower %d to tower %d\n",n,s,d);
- Hanoi(n-1,a,s,d);
- }
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- Hanoi(n,1,2,3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement