Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

iOS and MacOS / Tohanoi

Author
Message
NIKITA VASIREDDY
User Offline
Joined: 26th Sep 2016
Location:
Posted: 26th Sep 2016 15:02
#include<iostream>
#include<stdlib.h>
using namespace std;
void movedisks(int n,char a,char b,char c);
main()
{​int ch,n;
​cout<<"\nConsidering source peg is A and destination peg is C\n";
​cout<<"And the top most disk is the smallest and is numbered as 1\n";
​cout<<"\n1.Play\n2.Exit\n";
​while(1)
​{​cout<<"Enter choice : ";
​​cin>>ch;
​​switch(ch)
​​{
​​​case 1 : cout<<"\nenter the number of disks : ";
​​​​cin>>n;
​​​​movedisks(n,'A','B','C');
​​​​cout<<"\nFINISHED!!!\n\n";
​​​​break;
​​​case 2 : exit(0);
​​}
​}

};
void movedisks(int n , char a,char b, char c)
{​​
​if(n>=1)
​{​
​​movedisks(n-1,a,c,b);
​​cout<<"\nMove disk "<<n<<" from peg "<<a<<" to peg "<<c<<endl;
​​movedisks(n-1,b,a,c);
​}

}​

Login to post a reply

Server time is: 2017-03-27 02:57:11
Your offset time is: 2017-03-27 02:57:11