Skip to content

Commit

Permalink
tower of hanoi
Browse files Browse the repository at this point in the history
  • Loading branch information
nehal5913 authored Oct 6, 2018
1 parent cd249bc commit 5449edd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tower of hanoi
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<iostream>
using namespace std;

void TOH(int n,char Sour, char Aux,char Des)
{
if(n==1)
{
cout<<"Move Disk "<<n<<" from "<<Sour<<" to "<<Des<<endl;
return;
}

TOH(n-1,Sour,Des,Aux);
cout<<"Move Disk "<<n<<" from "<<Sour<<" to "<<Des<<endl;
TOH(n-1,Aux,Sour,Des);
}

int main()
{
int n;

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

return 0;
}

0 comments on commit 5449edd

Please sign in to comment.