Switch to full style
C++ code examples
Post a reply

Solving the Tower of Hanoi problem using C++

Wed Jan 23, 2013 4:35 pm

Solving the Tower of Hanoi problem using C++ implementation
cpp code
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main()
{
int n,i;
char choise;

do
{
int sum=1;
cout<<"\n\n\t\t\tThe number of disks = ";
cin>>n;
for(i=0;i<n;i++)
sum*=2;
sum-=1;
cout<<"\n\n\tThe number of minimum trials = "<<sum<<endl;
int x;

printf( "How many disks? " );
scanf( "%d", &n );
puts( "\n\n" );

for (x=1; x < (1 << n); x++)
printf( "\t\tmove from pole %i to pole %i.\n",
(x&x-1)%3, ((x|x-1)+1)%3 );
cout<<"\n\n\n\tDo you want check another number?(y/n). ";
cin>>choise;
}while(choise=='y'||choise=='Y');
cout<<endl<<endl<<endl;
cout<<" *** WITH MY BEST WISHES ***"<<endl;

cout<<" <><>"<<endl;
cout<<"Type EXIT to close the program : ";
cin>>choise;
return 0;
}




Post a reply
  Related Posts  to : Solving the Tower of Hanoi problem using C++
 Tower of Hanoi     -  
 solving fibonacci sequence recursively     -  
 simple Ajax library solving back button and bookmarks     -  
 solving dojox/mobile/Heading moveTo function bug issue     -  
 i have problem     -  
 MVC problem....     -  
 Skymiles [3.04] little? problem     -  
 Paging problem in php     -  
 Windows problem!!!     -  
 Map Class problem     -  

Topic Tags

C++ Algorithms