Created
February 21, 2020 13:17
-
-
Save gabrielsaints/538dfe8a45960005dff26e7f386fa94f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 disks ; | |
cout<< "HANOI TOWER\n\n"; | |
cout<< "Number of disks: "; | |
cin>> disks; | |
cout<<"\nMovements: "; | |
cout<< hanoi(disks); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment