Advertisement
EckOp

Thap Ha Noi

Jun 5th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. void _HaNoiTower(int n, string nguon, string tg, string dich);
  4. int main() {
  5.     int n;
  6.     cout << "Nhap so dia n = ";
  7.     cin >> n;
  8.     _HaNoiTower(n,"a", "b", "c");
  9.     return 0;
  10. }
  11. void _HaNoiTower(int n, string nguon, string tg, string dich) {
  12.     if (n == 1) cout << "\nDi chuyen dia "<<n<<" tu cot "<<nguon<<" sang cot "<< dich;
  13.     else {
  14.         _HaNoiTower(n-1,nguon, dich,tg);
  15.         cout << "\nDi chuyen dia "<< n <<" tu cot "<< nguon <<" sang cot "<< dich;
  16.         _HaNoiTower(n-1,tg, nguon,dich);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement