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