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