It follows some rules: Those are Here
/*
--------------------------------------------
Program
to implement TOWER OF HANOI PROBLEM.
http://native-code.blogspot.com
--------------------------------------------
*/
#include<stdio.h>
#include<conio.h>
void hanoi_tower(char,char,char,int);
int i=0;
void main()
{
int n;
clrscr();
printf("\t\t\t\t ! TOWER OF
HANOI PROBLEM !");
printf("\n Input the no. of
Disc : ");
scanf("%d",&n);
printf("\n Tower of Hanoi
for %d DISC",n);
hanoi_tower('X','Y','Z',n);
getch();
}
void hanoi_tower(char peg1,char peg2,char peg3, int n)
{
if(n<=0)
printf("\n Illegal
Entry");
if(n==1)
{
i++;
printf("\n Step No. ->
%d",i);
printf(" ==> Move Disk
from %c to %c",peg1,peg3);
}
else
{
hanoi_tower(peg1,peg3,peg2,n-1);
hanoi_tower(peg1,peg2,peg3,1);
hanoi_tower(peg2,peg1,peg3,n-1);
}
}
Post a Comment