#include<stdio.h>
int
TOWER(int
n, char
beg, char
aux, char
end);
int
TOWER(int
n, char
beg, char
aux, char
end)
{
if
(n==1)
printf("\nmove disk %d from %c to %c",
n, beg, end);
else
{
TOWER(n-1,beg,end,aux);
printf("\nmove disk %d from %c to %c",
n, beg, end);
TOWER(n-1,aux, beg,
end);
return
0;
}
}
int
main()
{
int
n;
printf("TOWER OF HANOI:\n");
printf("\nHow many disk:
");
scanf("%d",
&n);
if(n<1)
{
printf("INVALID DISK MOVEMENT");
return
0;
}
TOWER(n,'A', 'B', 'C');
return
0;
}
|
Code: Towers of hanoi - write a program to solve Towers of Hanoi -
Subscribe to:
Post Comments (Atom)
nice,,,,,,,,,,
ReplyDeleteplz exlain how it execute
ReplyDeleteI am going to explain algorithm and a sample map on this problem very soon.
ReplyDelete