Untitled

 avatar
user_7016102
plain_text
24 days ago
387 B
2
Indexable
Never
//LAB 9
#include<iostream>
using namespace std;
int TOH(int n,char a,char b,char c)
{
	if(n==1)
	{
		cout<<"Move disk from "<<a<<"to "<<c<<endl;
	}
	else{
		TOH(n-1,a,c,b);
		cout<<"Move disk from "<<a<<"to "<<b<<endl;
		TOH(n-1,b,a,c);
	}
}
int main()
{
    int n;
    cout << "Enter the number of disks: ";
    cin >> n;
    TOH(n, 'A', 'B', 'C');
    return 0;
}
Leave a Comment