# include<stdio.h>
# include<conio.h>
void move(int n,char beg,char end,char aux);
void main()
{
int n;
clrscr();
printf("\t\t\t\tTOWER OF HANOI");
printf("\n\n Enter the number of disks: ");
scanf("%d",&n);
printf("\n The disks 1,2,3... are in the increasing order of their sizes.\n\n");
move(n,'A','B','C');
getch();
}
void move(int n,char beg,char aux,char end)
{
if(n>0)
{
move(n-1,beg,end,aux);
printf(" Move disk %d from Peg %c to Peg %c\n",n,beg,end);
getch();
move(n-1,aux,beg,end);
}
}
# include<conio.h>
void move(int n,char beg,char end,char aux);
void main()
{
int n;
clrscr();
printf("\t\t\t\tTOWER OF HANOI");
printf("\n\n Enter the number of disks: ");
scanf("%d",&n);
printf("\n The disks 1,2,3... are in the increasing order of their sizes.\n\n");
move(n,'A','B','C');
getch();
}
void move(int n,char beg,char aux,char end)
{
if(n>0)
{
move(n-1,beg,end,aux);
printf(" Move disk %d from Peg %c to Peg %c\n",n,beg,end);
getch();
move(n-1,aux,beg,end);
}
}
0 comments :
Post a Comment