Skip to content
Open
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
29 changes: 29 additions & 0 deletions Tower_of_hanoi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<bits/stdc++.h>
using namespace std;

string tower(int n,char s,char a,char d)
{
if(n==1)
{
cout<<" "<<s<<" "<<d<<endl;
return " ";
}
tower(n-1,s,d,a);
cout<<" "<<s<<" "<<d<<endl;
tower(n-1,a,s,d);
}

int main()
{
int n;

cout<<"Enter no. of disks:";
cin>>n;
//calling the TOH
tower(n,'A','B','C');

return 0;


return 0;
}