Close
Login to Your Account
Faadooengineers
Results 1 to 4 of 4

Thread: tower ofa hanoi problems

Popular topic for study

Connected component of a graph

The connected component of a graph is a maximal subgraph of a given graph, which is connected. Read this topic
  1. #1
    Fuchcha FaaDoO Engineer
    Join Date
    Oct 2013
    Posts
    1

    Branch: : Aeronautical Engineering

    Chat tower of hanoi problems

    TOWERS OF HANOI

    1.Suppose three pegs,labeled as A,B,C.
    2.On peg a there are placed n disks with decreasing size.(means top disk is small and bottom disk is larger)
    OBJECTIVE:

    We have to move the disks from peg A to C using B as auxilary peg.

    following that rules:
    1.
    Only one disk can be moved at a time (means only topmost disk from any peg can be moved)

    2.At no time a larger disk can be placed on a smaller disk.



    Algorithm for towers of hanoi:

    Tower(N,A,B,C) (where n is the number of disks.)

    the procedure gives a recursive solution for the problem of tower of hanoi.
    1.if N=1,then:
    a)Write:A->C
    b)return.
    2.(Move N-1 disks from A->B)
    CAll Tower(N-1,A,C,B)
    3.Write A->B
    4.(Move N-1 disks from B->C)
    Call Tower(N-1,B,A,C)
    5.Return.




    PROGRAME
    1. #include <stdio.h>
    2. void towers(int, char, char, char);
    3. int main()
    4. {
    5. int num;
    6. printf("Enter the number of disks : ");
    7. scanf("%d", &num);
    8. printf("The sequence of moves involved in the Tower of Hanoi are :");
    9. towers(num, 'A', 'C', 'B');
    10. return 0;
    11. }
    12. void towers(int num, char frompeg, char topeg, char auxpeg)
    13. {
    14. if (num == 1)
    15. {
    16. printf("Move disk 1 from peg %c to peg %c", frompeg, topeg);
    17. return;
    18. }
    19. towers(num - 1, frompeg, auxpeg,topeg);
    20. towers(num - 1, auxpeg, topeg, frompeg);
    21. }


    Last edited by ajaytopgun; 3rd April 2014 at 11:38 AM.

  2. #2
    Fuchcha FaaDoO Engineer
    Join Date
    Nov 2013
    Posts
    2

    Branch: : Aeronautical Engineering

    Re: tower ofa hanoi problems

    so what u want u ask?????be specific......

  3. #3
    Sr. FaaDoO Engineer
    Join Date
    Jan 2014
    Posts
    52

    Branch: : Aeronautical Engineering

    Re: tower of hanoi problems

    thanks for sharing this algorithm..

  4. #4
    Fuchcha FaaDoO Engineer
    Join Date
    Jan 2015
    Posts
    3

    Gender: : Male

    Branch: : Computer Science Engineering

    City : Chandigarh*

    Re: tower ofa hanoi problems

    What you want to ask in tower of hanoi problem? Be specific.

Tags for this Thread