Thread: towers

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    towers

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void tower ( int number, int peg1, int peg2, int peg3 );
    
    int main(void)
    {
     int num, peg1, peg2, peg3;
     peg1 = 1, peg2 = 2, peg3 = 3;
    
     printf("?");
     scanf( "%d", &num );
    
     tower(num, peg1, peg2, peg3 );
    
          system("PAUSE");
          return 0;
    }
    
    void tower ( int number, int peg1, int peg2, int peg3 )
    {
    
     if ( number == 1 ){
        printf( "%d --> %d\n", peg1, peg3 );
     }
     else{
         tower( number -1 , peg1, peg2, peg3 );
         printf( "%d --> %d\n", peg1, peg2 );
         tower( number -1, peg1, peg3, peg2 );
         printf( "%d --> %d\n", peg1, peg2 );
         tower( number -1 , peg2, peg3, peg1 );
         printf("%d --> %d\n", peg1, peg2 );
     }
    }
    Hi well this is like my fourth recursive function programm i did skip the recursion chapter in the text book ..now i am having problems ... well i do know how recursion works i have done some examples on recursion like about 3...
    Well this is what the author says

    1. Move n-1 disk from peg 1 to peg 2 , using peg3 as a temp holding area
    2.Move the last disk (largest) from peg1 to peg2 ...okay i have a prob with this one
    3. Move the n-1 disk from peg 2 to peg 3, using peg1 as a temp holdong area..

    Thanks alot
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    And your question is??
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    Originally posted by Stoned_Coder
    And your question is??
    and my question is *dum dum da dum da dum da da ta dum * my code isnt working properly
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  4. #4
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Wink


    did skip the recursion chapter in the text book ..now i am having problems ... well i do know how recursion works i have done some examples on recursion like about 3...
    Well this is what the author says

    The towers program is a common recursive problem. Maybe the chapter you skipped will have something about it.
    Mr. C: Author and Instructor

  5. #5
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    guys plzz help me out i really do need a lil help
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. towers of hanoi - what is wrong with this code?
    By kanesoban in forum C Programming
    Replies: 4
    Last Post: 09-17-2007, 01:20 PM
  2. Towers of Hanoi (need help)
    By Loudan in forum C++ Programming
    Replies: 3
    Last Post: 01-30-2006, 10:17 PM
  3. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  4. Towers of Hanoi, special output.
    By spoon_ in forum C Programming
    Replies: 3
    Last Post: 03-15-2003, 06:08 PM
  5. Towers of Hanoi
    By janehung in forum C Programming
    Replies: 12
    Last Post: 01-07-2002, 06:40 AM