rodan0818

Solving Tower OF Hanoy Using Recursion in C

Jun 13th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include<stdio.h>
  2. void toh(int n,char s,char d ,char t)
  3. {
  4.     if(n==1)
  5.     {
  6.  
  7.         printf("MOVE DISK %d From %c to %c\n",n,s,d);
  8.  
  9.     }
  10.     else
  11.         {
  12.        toh(n-1,s,t,d);
  13.        printf("MOVE DISK %d From %c to %c\n",n,s,d);
  14.        toh(n-1,t,d,s);
  15.  
  16.     }
  17. }
  18. int main(void)
  19. {
  20.     printf("Enter the Number Of Disks to move\n");
  21.     int n;
  22.     scanf("%d",&n);
  23.     toh(n,'S','D','T');
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment