Skip to content

Commit

Permalink
Merge pull request #78 from bistakazi101/main
Browse files Browse the repository at this point in the history
TowerofHanoi solved c++
  • Loading branch information
mrsamirr authored Oct 22, 2023
2 parents 7b9b23f + b5c0cd4 commit e8c4afe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"files.associations": {
"iostream": "cpp"
}
}
Binary file added C++/TowerofHanoi
Binary file not shown.
22 changes: 22 additions & 0 deletions C++/TowerofHanoi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
using namespace std;

void towerOfHanoi(int n, char source, char auxiliary, char destination) {
if (n == 1) {
cout << "Move disk 1 from " << source << " to " << destination << endl;
return;
}

towerOfHanoi(n - 1, source, destination, auxiliary);
cout << "Move disk " << n << " from " << source << " to " << destination << endl;
towerOfHanoi(n - 1, auxiliary, source, destination);
}

int main() {
int n;
cout << "Enter the number of disks: ";
cin >> n;

towerOfHanoi(n, 'A', 'B', 'C');
return 0;
}

0 comments on commit e8c4afe

Please sign in to comment.