You are invited to Log in or Register a free Frihost Account!

# Towers Of HANOI

Hello Friends!!
The Towers Of HANOI

->The Tower of Hanoi is also called the Tower of Brahma.
->is a mathematical game or puzzle.
->It consists of three rods, and a number of disks of different sizes.
->The puzzle starts with the disks in a neat stack in ascending order of size on one rod.
->The smallest at the top, thus making a conical shape.
->_"RULES"_
->Only one disk may be moved at a time.
->Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod.
->No disk may be placed on top of a smaller disk.
->The puzzle was invented by the French mathematician Édouard Lucas in 1883.
->There is a legend about an Indian temple which contains a large room with three time-worn posts in it surrounded by 64 golden disks. Brahmin priests, acting out the command of an ancient prophecy, have been moving these disks, in accordance with the rules of the puzzle, since that time. The puzzle is therefore also known as the Tower of Brahma puzzle.
->The number of moves required to solve a Tower of Hanoi puzzle is 2n-1, where n is the number of disks.

""""Towers of Hanoi(Recursion)""""

#include<stdio.h>
#include<conio.h>
#include<math.h>
void hanoi(int x, char from,char to,char aux)
{

if(x==1)
{
printf("Move Disk From %c to %c\n",from,to);
}
else
{
hanoi(x-1,from,aux,to);
printf("Move Disk From %c to %c\n",from,to);
hanoi(x-1,aux,to,from);
}

}
void main()
{
int disk;
int moves;
clrscr();
printf("Enter the number of disks you want to play with:");
scanf("%d",&disk);
moves=pow(2,disk)-1;
printf("\nThe No of moves required is=%d \n",moves);
hanoi(disk,'A','C','B');
getch();
}