#include<stdio.h>
#include<conio.h>
void hanoi(int,char,char,char);
int n;
char beg='B',mid='M',end='E';
void main()
{
clrscr();
printf(".........PROGRAM TO IMPLEMENT THE TOWER OF HANOI.......");
printf("\n\n\n\n\nHow many disks::=>");
scanf("%d",&n);
hanoi(n,beg,mid,end);
getch();
}
void hanoi(int n,char beg,char mid,char end)
{
if(n>0)
{
hanoi(n-1,beg,end,mid);
printf("\nTransfer %d from %c to %c",n,beg,end);
hanoi(n-1,mid,beg,end);
}
}
#include<conio.h>
void hanoi(int,char,char,char);
int n;
char beg='B',mid='M',end='E';
void main()
{
clrscr();
printf(".........PROGRAM TO IMPLEMENT THE TOWER OF HANOI.......");
printf("\n\n\n\n\nHow many disks::=>");
scanf("%d",&n);
hanoi(n,beg,mid,end);
getch();
}
void hanoi(int n,char beg,char mid,char end)
{
if(n>0)
{
hanoi(n-1,beg,end,mid);
printf("\nTransfer %d from %c to %c",n,beg,end);
hanoi(n-1,mid,beg,end);
}
}
No comments:
Post a Comment