#include <stdio.h>
void hanoifxn(int n, char fr, char tr, char ar)//fr=from rod,tr =to rod, ar=aux rod
{
if (n == 1)
{
printf("\n Move disk 1 from rod %c to rod %c", fr, tr);
return;
}
hanoifxn(n-1, fr, ar, tr);
printf("\n Move disk %d from rod %c to rod %c", n, fr, tr);
hanoifxn(n-1, ar, tr, fr);
}
int main()
{
int n = 4; // n is equal to the number of discs
hanoifxn(n, 'A', 'C', 'B'); // A, B and C are the name of rod
return 0;
}
void hanoifxn(int n, char fr, char tr, char ar)//fr=from rod,tr =to rod, ar=aux rod
{
if (n == 1)
{
printf("\n Move disk 1 from rod %c to rod %c", fr, tr);
return;
}
hanoifxn(n-1, fr, ar, tr);
printf("\n Move disk %d from rod %c to rod %c", n, fr, tr);
hanoifxn(n-1, ar, tr, fr);
}
int main()
{
int n = 4; // n is equal to the number of discs
hanoifxn(n, 'A', 'C', 'B'); // A, B and C are the name of rod
return 0;
}
Bhuvan Arora
No comments:
Post a Comment