Monday, 20 June 2011

Tower of Hanoi Programm in c++

#include<iostream.h>

void move(int n,char *b,char *a,char *e)
{
 if(n>0)
 {
  move(n-1,b,e,a);
  cout<<"disk "<<n<<" is moved from "<<b<<" to "<<e<<endl;
    move(n-1,a,b,e);
 }
}

void main()
{
 cout<<"\n";
 cout<<"Enter the no. of disks: ";
 int n;
 cin>>n;
 move(n,"beg","aux","end");
}
Editing & Program by 'Shojib'

No comments:

Post a Comment