Tower of Hanoi

PHOTO EMBED

Tue Oct 12 2021 02:18:40 GMT+0000 (UTC)

Saved by @code_ea

#include <iostream>
using namespace std;


void ToH(int n, char A, char B, char C) 
{ 
    if (n == 1) 
    { 
        cout<<"Move 1 from " <<  A << " to " << C << endl; 
        return; 
    } 
    ToH(n-1, A, C, B); 
    cout<<"Move " << n << " from " <<  A << " to " << C << endl; 
    ToH(n-1, B, A, C); 
}
	
int main() {
	
	int n = 2; 
    
    ToH(n, 'A', 'B', 'C'); 
	
	return 0;
}
content_copyCOPY

https://ide.geeksforgeeks.org/nWJa51G8B8