Created
October 24, 2016 14:15
-
-
Save mostafa6765/11dda3d2d8f53769a1f135ec35827d8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ************************************* | |
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