Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions Tower of hanoi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<bits/stdc++.h>

using namespace std;

void TOH(int n, int A, int B, int C){
if(n>0){
TOH(n-1,A,C,B);
cout<<"("<<A<<","<<C<<")"<<endl;
TOH(n-1,B,A,C);
}
}

int main(){
int n,A,B,C; //Here A, B and C are tower numbers
cin>>n>>A>>B>>C;
cout<<"The order of moves will be: "<<endl;
TOH(n,A,B,C);

return 0;
}