SHARE
TWEET

C Tower of Hanoi

naeem043 Sep 27th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top