Total members 11894 |It is currently Sat Nov 23, 2024 5:20 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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;
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  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






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com