Return to Snippet

Revision: 69077
at April 16, 2015 08:28 by agarcia


Initial Code
#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
}

Initial URL

                                

Initial Description
Hanoi tower solver

Initial Title
Hanoi towers by Aniol Garcia

Initial Tags

                                

Initial Language
C++