Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Towers of Hanoi

Posted on 1997-05-20
1
Medium Priority
?
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
yonat earned 60 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

704 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