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.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.

 #include <stdio.h>

void tHanoi(int n,char from_rod,char to_rod,char aux_rod) 


{


    if(n==1){


        printf("\nMove disk 1 from rod %c to rod %c",from_rod,to_rod);


        return; }


    tHanoi(n-1,from_rod,aux_rod,to_rod);


    printf("\nMove disk %d from rod %c to rod %c",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; 

    

}

Comments

Popular posts from this blog

Elavenil has a chessboard with N rows and M columns. In one step, he can choose two cells of the chessboard which share a common edge (that has not been cut yet) and cut this edge. Formally, the chessboard is split into two or more pieces if it is possible to partition its cells into two non-empty subsets S1 and S2 (S1∩S2=∅, |S1|+|S2|=NM) such that there is no pair of cells c1,c2 (c1∈S1,c2∈S2) which share a common edge that has not been cut.Elavenil does not want the board to split into two or more pieces. Compute the maximum number of steps he can perform while satisfying this condition.

Mukesh and Salima was looking to buy Organic Apples in the nearest fruits shop.But Shop Owner mixed the Hybrid apples in that Apple box. After sometimes Mukesh checking the box, he was confused among organic and hybrid apple. He started to count the hybrid apples. Please help to Mukesh Count the total number of hybrid apples in the box.

The Matriculation school have arranged an Annual Day Function.Volunteers have decorated a floor on various places of the school using Rose and Tulip flowers. But one of the coordinators requested the volunteers to rearrange the decoration like a triangular size.Coordinator also told them that tulips flowers need to be positioned at the middle of the roses