Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int r1=0, r2=0;
- void towerOfHanoi(int n, char sourceRod, char tempRod, char destinationRod)
- {
- if (n == 1)
- {
- printf("\nMove the disk 1 from rod %c to rod %c\n", sourceRod,destinationRod);
- return;
- }
- towerOfHanoi(n-1, sourceRod, destinationRod, tempRod);
- printf("\nMove the disk %d from rod %c to rod %c\n", n, sourceRod, destinationRod);
- towerOfHanoi(n-1, tempRod, sourceRod, destinationRod);
- }
- int main()
- {
- int disks;
- printf("\nEnter the number of disks: ");
- scanf("%d",&disks);
- towerOfHanoi(disks,'A','B','C');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement