Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- void hanoi(int, char, char, char);
- int move_count;
- int disks;
- int main()
- {
- printf("Enter the number of disks : ");
- scanf("%d",&disks);
- move_count = pow(2,disks)-1;
- printf("\nTotal moves: %d\n\n",move_count);
- printf("Moves to be made :\n\n");
- hanoi(disks, 'S', 'I', 'D');
- return 0;
- }
- void hanoi(int disk_number, char s, char i, char d)
- {
- if(disk_number == 1)
- {
- printf("Move disk from %c to %c\n", s, d);
- }
- else
- {
- hanoi(disk_number-1, s, d, i);
- printf("Move disk from %c to %c\n", s, d);
- hanoi(disk_number-1, i, s, d);
- }
- }
Add Comment
Please, Sign In to add comment