its difficult for me to understand argument exchange in the transfer function . a detail explanation will be really helpfull.
Code:
/* The TOWERS OF HANOI- solver using recursion*/
Code:
#include<stdio.h>
void transfer (int n, char from, char to , char temp);
void main()
{
int n;
printf(" Welcome to the TOWERS OF HANOI\n\n");
printf("How many disks?");
scanf("%d", &n);
printf("\n");
transfer (n,'L','R','C');
}
void transfer ( int n, char from, char to, char temp)
{
if(n>0)
{
transfer(n-1,from,temp,to);
printf("Move disk %d from %c to %c\n",n, from,to);
transfer(n-1, temp,to,from);
}
return;
}
in the void transfer function , argument from ,to, temp receives - L,R, M respectively. then within the bracket -
Code:
Code:
{
transfer(n-1,from,temp,to);
printf("Move disk %d from %c to %c\n",n, from,to);
transfer(n-1, temp,to,from);
}
in the first transfer what will receive by from=
temp=
to=
and they will pass to void transfer function as well ?
And for 2nd transfer what will received by temp, to , from and what they will transfer to void transfer function as well ?