In this program number of disks(entered by user) are transfered from left right using recursion following condition that smaller disk always comes over the bigger disk.
#include #include
void tower_of_hanoi(int n, char LEFT, char RIGHT, char CENTER) { if(n>0) { tower_of_hanoi(n-1, LEFT, CENTER, RIGHT); printf("\n\tMove disk %d from %c to %c", n, LEFT, RIGHT); tower_of_hanoi(n-1, CENTER, RIGHT, LEFT); } }
void main() { int n; printf("\nEnter no. of disks: "); scanf("%d",&n); clrscr(); printf("\nSOLUTION \n\t (L=Left,R=Right,C=Ceter)\n"); tower_of_hanoi(n,'L','R','C'); }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|