If Any Required Program Please Ask In Comment I Will Help You(any Program in JAVA or C++) . . THANKS FOR VISITING MY BLOG!

If U LIKE MY PROFILE RAISE YOUR HAND IF U NOT RAISE UR STANDARD. Powered by Blogger.

Sunday, October 21, 2018

PROGRAM FOR Tower Of Hanoi.



#include <iostream>
#include <stdlib.h>
#include <conio.h>

using namespace std;

int TOH(int, char, char, char );

int main()
{
int No;

cout << "Enter Number Of Disks: ";
cin >> No;

TOH(No, 'A', 'B', 'C');

    getch();
return 0;

}

int TOH(int N, char Src, char Aux, char Dest)
{
if (N == 1)
    {
        cout << "\nMove Disk " << N << " from " << Src << " to " << Dest <<endl;
        return 0;
    }
       TOH(N - 1, Src, Dest, Aux);
   cout << "\nMove Disk " << N << " from " << Src << " to " << Dest << endl;

   TOH(N - 1, Aux, Src, Dest);
}

0 comments:

Post a Comment