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
Solved

Towers of Hanoi

Posted on 1997-05-20
1
504 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

856 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