Skip to content

Instantly share code, notes, and snippets.

@m-zakeri
Created January 29, 2018 18:26
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 m-zakeri/86347217419ad3569affd328c0c822e0 to your computer and use it in GitHub Desktop.
Save m-zakeri/86347217419ad3569affd328c0c822e0 to your computer and use it in GitHub Desktop.
/*
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