Printing a centric square using recursion

This is a discussion on Printing a centric square using recursion within the C Programming forums, part of the General Programming Boards category; First off let me just say that I am not a big fan of recursion and am having a bit ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    1

    Printing a centric square using recursion

    First off let me just say that I am not a big fan of recursion and am having a bit of a hard time getting my head around how to do this.

    What we need to do is have the user enter a string ex. "cat" then using recursion we need to print it out like this:

    1 T T T T T
    2 T A A A T
    3 T A C A T
    4 T A A A T
    5 T T T T T

    The only hints we got was that lines 1 & 5, and 2 & 4 are the same and to make it easier we should only run through the recursive loop 3 times and then just reprint strings 2 and 1 after the initial 3 times through.

    Like I said I cant seem to get my head around recursion. I can follow a trace and what not, just cant seem to come up with how to go about this.

    Thanks in advance.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Well, it's symmetrical around the center so you should reuse the same "stuff" on both sides of the recursive call:
    Code:
    void Func()
    {
      Stuff;
      Func(); //Recursion
      Stuff; //Same stuff as above
    }
    Implemented correctly you could create patterns like:
    Code:
    C
    A(C)A
    T(ACA)T
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tic Tac Toe Comp Move help
    By swgh in forum C++ Programming
    Replies: 5
    Last Post: 09-24-2008, 11:05 AM
  2. Loop seg error
    By Zishaan in forum Game Programming
    Replies: 2
    Last Post: 03-28-2007, 01:27 PM
  3. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  4. Help with my draughts game
    By Zishaan in forum C++ Programming
    Replies: 9
    Last Post: 03-24-2007, 07:33 AM
  5. printing a btree using recursion
    By agerealm in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2003, 07:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21