Solved

Towers of Hanoi

Posted on 1997-05-20
1
499 Views
Last Modified: 2008-03-17
I need to get the code for the towers of hanoi in c++
I have been trying for days to figure it out.
"please help"
0
Comment
Question by:denver
1 Comment
 
LVL 5

Accepted Solution

by:
yonat earned 20 total points
ID: 1163587
#include <iostream.h>

void Hanoi(char source, char temp, char destination, int n)
/* This functions takes a tower of n disks and moves from peg  */
/* 'source' to peg 'destination'.  Peg 'temp' may be used      */
/* temporarily.                                                */
{
        if (n>0)
        {
        Hanoi (source, destination, temp, n-1);
        cout << "Move disk "<<< n << " from peg " << source <<
                " to peg " << destination << ".\n";
        Hanoi ( temp, source, destination, n-1);
        }
}

main()
{       int n;
        cout << "Enter the number of disks: ";
        cin >> n;
        cout << '\n';
        Hanoi('A','B','C',n);
}


0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maze travler 6 55
Unable to build a Win32 solution with EXE and DLL projects inside: Visual Studio 2010 3 100
Compile GLUT with Visual Studio 2015 1 149
Header of docx file 17 103
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question