Advertisement
Sathvikks8

Tower_of_Hanoi.c

Sep 27th, 2020
69
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. int r1=0, r2=0;
  3. void towerOfHanoi(int n, char sourceRod, char tempRod, char destinationRod)
  4. {
  5.   if (n == 1)
  6.   {
  7.     printf("\nMove the disk 1 from rod %c to rod %c\n", sourceRod,destinationRod);
  8.     return;
  9.   }
  10.   towerOfHanoi(n-1, sourceRod, destinationRod, tempRod);
  11.   printf("\nMove the disk %d from rod %c to rod %c\n", n, sourceRod, destinationRod);
  12.   towerOfHanoi(n-1, tempRod, sourceRod, destinationRod);
  13. }
  14.  
  15. int main()
  16. {
  17.   int disks;
  18.   printf("\nEnter the number of disks: ");
  19.   scanf("%d",&disks);
  20.   towerOfHanoi(disks,'A','B','C');
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement