Advertisement
rofllmaolol

hanoi

Jan 29th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. void hanoi(int n, char a, char b, char c)
  5. {
  6.  
  7.     if(n==1)
  8.         cout<<a<<"-"<<b<<endl;
  9.     else
  10.     {
  11.         hanoi(n-1,a,c,b);
  12.        cout<<a<<"-"<<b<<endl;
  13.         hanoi(n-1,c,b,a);
  14.     }
  15. }
  16.  
  17. int main()
  18. {
  19.     char a,b,c;
  20.     int n;
  21.     cin>>n;
  22.     a='a';
  23.     b='b';
  24.     c='c';
  25.     hanoi(n,a,b,c);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement