#include<conio.h>
#include<stdio.h>
void toh(int n,char a,char b,char c)
{
if(n==1)
{
printf("\nDisk %d - From %c To %c",n,a,c);
return;
}
toh(n-1,a,c,b);
printf("\nDisk %d - From %c To %c",n,a,c);
toh(n-1,b,a,c);
}
void main()
{
int n;
clrscr();
printf("Enter No. of Disk :");
scanf("%d",&n);
toh(n,'A','B','C');
getch();
}
#include<stdio.h>
void toh(int n,char a,char b,char c)
{
if(n==1)
{
printf("\nDisk %d - From %c To %c",n,a,c);
return;
}
toh(n-1,a,c,b);
printf("\nDisk %d - From %c To %c",n,a,c);
toh(n-1,b,a,c);
}
void main()
{
int n;
clrscr();
printf("Enter No. of Disk :");
scanf("%d",&n);
toh(n,'A','B','C');
getch();
}
No comments:
Post a Comment