Advertisement
achulkov2

Untitled

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