/ Published in: C++

Hanoi tower solver
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <iostream> using namespace std; void hanoi(int n, char origen, char desti, char aux) { if(n != 0) { hanoi(n-1,origen,aux,desti); cout << origen << " => " << desti << endl; hanoi(n-1,aux, desti, origen); } } int main() { int n; cout << "Introdueix el nombre de discs: "; cin >> n; cout << "Els moviments que s'han de fer:\n"; hanoi(n,'L','M','R'); // transfereix n discos de L a R utilitzant M }
Comments
