Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int k;
- void Hanoi(int n, int t1, int t2, int t3)
- {
- if(n == 1)
- cout << "Mutarea numarul " << ++k << '\n' << t1 << " -> " << t3 << '\n';
- else
- {
- Hanoi(n - 1, t1, t3, t2);
- cout << '\n';
- cout << "Mutarea numarul " << ++k << '\n' << t1 << " -> " << t3 << '\n'; // Mutam cel mai mare disc de pe t1 pe t3
- Hanoi(n - 1, t2, t1, t3); // Mutam cele n-1 discuri de pe t2 pe t3
- // folosind ca intermediar tija t1
- }
- }
- int main(void)
- {
- int n;
- cout << "Dati numarul de discuri: ";
- cin >> n;
- Hanoi(n, 1, 2, 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement