Laaslya is planning to go to the cinema theater to spend her weekend vacation. Her friends Tina, Caleb, and Jocelyn all knew about Laasya’s plan. They say we are coming too, but she thinks to ignore them because only Laasya has enough money to pay for the cinema ticket.
Laasya is very good at programming, so she puts up a puzzle to avoid taking her friends to the cinema. She also says that those who have finished this can come with me.
The puzzle is Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod. the number of the disk will be given as input obeying the following simple rules:
1) Only one disk can be moved at a time.
2) Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
3) No disk may be placed on top of a smaller disk.
Input:
The input represents the single line integer “n”
Output:
Display the Movement of the disk.
#include <stdio.h> void tHanoi(int n,char from_rod,char to_rod,char aux_rod) { if(n==1) {printf("Move disk 1 from rod %c to rod %c\n",from_rod,to_rod); return; } tHanoi(n-1,from_rod,aux_rod,to_rod); printf("Move disk %d from rod %c to rod %c\n",n,from_rod,to_rod); tHanoi(n-1,aux_rod,to_rod,from_rod); } int main() { int num; scanf("%d",&num); tHanoi(num,'A','C','B'); return 0; }
INPUT_1:
4
OUTPUT:
Move disk 1 from rod A to rod B
Move disk 2 from rod A to rod C
Move disk 1 from rod B to rod C
Move disk 3 from rod A to rod B
Move disk 1 from rod C to rod A
Move disk 2 from rod C to rod B
Move disk 1 from rod A to rod B
Move disk 4 from rod A to rod C
Move disk 1 from rod B to rod C
Move disk 2 from rod B to rod A
Move disk 1 from rod C to rod A
Move disk 3 from rod B to rod C
Move disk 1 from rod A to rod B
Move disk 2 from rod A to rod C
Move disk 1 from rod B to rod C
INPUT_2:
3
OUTPUT:
Move disk 1 from rod A to rod C
Move disk 2 from rod A to rod B
Move disk 1 from rod C to rod B
Move disk 3 from rod A to rod C
Move disk 1 from rod B to rod A
Move disk 2 from rod B to rod C
Move disk 1 from rod A to rod C
ILLUSTRATION
![](http://www.fcukthecode.com/wp-content/uploads/2022/01/Screenshot-from-2022-01-06-17-51-41.png)
Morae Q!
- Find how long will it take till the next fortune year from the current year.
- Find if it’s possible to distribute all the crayons into boxes and satisfy all the conditions.
- Compute sum of numbers using call by reference.
- Compute the amount of money to be handed over with conditions.
- Find the total number of beautiful triplets in the sequence.
- Find the total amount each worker has to pay individually.
- Find the minimum distance between any pair of equal elements in the array.
- Compute the maximum possible value of the given equation.
- Find the age of the student at the time of joining.
- Compute the total number of photos at each restaurant .
- Find the sum of digits of the number using Union datatype.
- Generate the details of the novels in the expected format.
- Sort the student details based on their names in ascending order.
- Find a way to move the king from current position to different square on chessboard.
- Find the time differences in the two different time zones.
- Identifying the greatest number with a numerator and denominator.
- Find the Minimum number of packages to supply all the bases.
- Tower of Hanoi, A puzzle.
- Compute the sum of array of elements using recursion method.
- Find the super digit of an integer using the rules.