Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
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
You can’t perform that action at this time.