Skip to content

Instantly share code, notes, and snippets.

@oca159
Forked from codepainkiller/hanoi.cpp
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oca159/8866bfcd35270f440725 to your computer and use it in GitHub Desktop.
Save oca159/8866bfcd35270f440725 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdlib>
using namespace std;
int hanoi(int n)
{
if(n == 1)
return 1;
else
return 2 * hanoi(n-1) + 1;
}
int main()
{
int discos ;
cout<< " TORRES DE HANOI \n\n";
cout<< "Numero de discos: ";
cin>> discos;
cout<<"\nMovimientos necesarios: ";
cout<< hanoi(discos);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment