Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Towers of Hanoi
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Alexandros, post: 1459641"] Constant escribió: Here you are a program wich solves the problem: #include <iostream> using namespace std; void hanoi (int nDisks, int pegA, int pegB, int pegC) { if (n>0) { hanoi (nDisks - 1, pegA, pegC, pegB); cout << "Move disk from peg " << pegA << " to peg " << pegC << endl; hanoi( nDisks-1, pegB, pegA, pegC); } } int main () { int n; cout << "Input number of disks: "; cin >> n; hanoi (n, 1, 2, 3); return 0; } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Towers of Hanoi
Top