Rule:-
The problem is to move all the disk from source to destination by the help of Via . A few rules to be followed for Tower of Hanoi are −
- 1) Only one disk can be moved among the towers at any given time.
- 2) Only the "top" disk can be removed.
- 3) No large disk can sit over a small disk.
solution:-
#include<stdio.h>
#include<conio.h>
// function for move the disk
void move(int n,char s,char d,char v)
{
if(n==1)
printf("\n move from %c to %c",s,d);
else
{
move(n-1,s,v,d);
move(1,s,d,v);
move(n-1,v,d,s);
}
}
int main()
{
int n;
printf("Enter nuber of disk");
scanf("%d",&n);
move(n,'A','C','B');
}
0 Comments