Advertisement
naeem043

C Tower of Hanoi

Sep 27th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. void moveDisk(char f,char t)
  5. {
  6.     printf("moving disk from %c to %c\n",f,t);
  7. }
  8. void moveTower(int h,char a, char b,char c)
  9. {
  10.     if(h > 0)
  11.     {
  12.         moveTower(h-1,a,c,b);
  13.         printf("Moving disk from %c to %c\n",a,c);
  14.         moveTower(h-1,b,a,c);
  15.     }
  16. }
  17.  
  18. int main()
  19. {
  20.     int n,total_move;
  21.     scanf("%d", &n,printf("Enter the Disk numbers: "));
  22.     total_move = pow(2,n)-1;
  23.     printf("Total Move %d\nHere the steps:\n", total_move);
  24.     moveTower(n,'A','B','C');  
  25.    
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement