Created
January 29, 2018 18:26
-
-
Save m-zakeri/86347217419ad3569affd328c0c822e0 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
/* | |
hanoi_tower in c | |
author: Abbas Aryanpoor | |
date: 2012 | |
www.micropedia.ir | |
*/ | |
#include <iostream> | |
#include <stdio.h> | |
#include <conio.h> | |
void tower(int,char,char,char); | |
int main() | |
{ | |
int ndisk; | |
system("cls"); | |
printf("\nEnter number of disks : "); | |
scanf("%d",&ndisk); | |
tower(ndisk,'A','B','C'); | |
_getch(); | |
return 0; | |
}//end of main() | |
void tower(int topN, char src,char aux,char dest) | |
{ | |
if(topN == 1) | |
{ | |
printf("\n Disk 1 from %c to %c ",src,dest); | |
} | |
else | |
{ | |
tower(topN-1,src,dest,aux); //src to aux | |
printf("\n Disk %d from %c to %c ",topN,src,dest); | |
tower(topN-1,aux,src,dest); //aux to dest | |
} | |
} | |
/* test input and output: | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment