Skip to content

Instantly share code, notes, and snippets.

@mostafa6765
Created October 24, 2016 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mostafa6765/11dda3d2d8f53769a1f135ec35827d8f to your computer and use it in GitHub Desktop.
Save mostafa6765/11dda3d2d8f53769a1f135ec35827d8f to your computer and use it in GitHub Desktop.
/* *************************************
Tower of Hanoi
Author:Md.Mostafa kamal
Author URI: https://mostafa.itnishi.com/
***************************************/
#include<iostream>
using namespace std;
void hanoi(int m, char a, char b,char c){
if(m==1){
cout<<"Move the disk from "<<a<<" to"<<b<<"\n";
}
else{
hanoi(m-1,a,c,b);
cout<<"Move disk from"<<a<<"to"<<b<<"\n";
hanoi(m-1,c,b,a);
}
}
int main(){
int n;
cout<<"how many discs: ";
cin>>n;
hanoi(n,'A','B','C');
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment