Total members 11895 |It is currently Fri Dec 27, 2024 5:26 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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

int main()
{
int n,i;
char choise;
cout<<" Cairo University "<<endl;
cout<<" Faculty of computers and information"<<endl;
cout<<" CS - MATH SOCIETY"<<endl;
cout<<" ---------------------"<<endl<<endl;
cout<<" INFINITY GROUP "<<endl;
cout<<" <><>\n"<<endl;
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<<" INFINITY GROUP "<<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 : Tower of Hanoi
 Solving the Tower of Hanoi problem using C++     -  



Topic Tags

C++ Algorithms
cron





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