/**
Module Name: Tower of Hanoi
Description: This Program is done using Recursion
Author: Tauqirul Haque
*/
void towerOfHanio(int, char, char, char);
int main()
{
clrscr();
int disk ;
printf("Enter The Number of Disk : ");
scanf("%d",&disk);
int move = (int)(pow(2,disk)-1);
printf("\nTotal Number of Moves are # %d \n",move);
towerOfHanio(disk, 'A','C','B'); // a= source, c = destination , b = temp
printf("\n");
return 0;
}
void towerOfHanio(int disk, char source, char destination, char temp)
{
if(disk == 1)
{
printf("Move : %c -> %c",source,destination);
}
else
{
towerOfHanio(disk-1, source, temp, destination);
printf("\nMove : %c -> %c \n",source,destination);
towerOfHanio(disk-1, temp, destination, source);
}
}
Comments