Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- void hanoi(int n,char from,char tmp,char to)
- {
- if (n>1)
- {
- hanoi(n-1,from,tmp,to);
- cout<<n<<" "<<from<<" "<<tmp<<endl;
- hanoi(n-1,to,tmp,from);
- cout<<n<<" "<<tmp<<" "<<to<<endl;
- hanoi(n-1,from,tmp,to);
- }
- else if (n==1)
- {
- cout<<n<<" "<<from<<" "<<to<<endl;
- }
- }
- main()
- {
- int n;
- cin>>n;
- hanoi(n,'1','2','3');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement