Jump to content

Recursion

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
jendana89

jendana89

    Newbie

  • Members
  • Pip
  • 2 posts
I am working on writing a simple program to make designs out of asterisks. I am having a lot of trouble coming up with the code to make this design though ( the underscores represent spaces from the left-most edge of the page):

*
**
_*
****
__*
__**
___*
********
____ *
____ **
_____ *
____ ****
_______*
_______**
________*

The method to make this design should be recursive, with a single parameter, n (the number of stars in the longest line). I supposed there could be a second parameter that could control the number of spaces the stars are moved over. The code should work for any number, but I think it looks better with simple numbers (2, 4, 8, 16, etc).

Any ideas are greatly appreciated!

#2
Deadlock

Deadlock

    Learning Programmer

  • Members
  • PipPipPip
  • 81 posts
Actually I can't see the figure you are trying to print. Can you post a screenshot?

#3
kmhosny

kmhosny

    Programmer

  • Members
  • PipPipPipPip
  • 133 posts
i think that there is a constant pattern that do not need to be changed you will only increase the spaces that you will use
*
**
_*
****
__*
__**
___*
as this pattern is repeated in the part you posted twice only with more spaces but i cant figure out how the spaces are increasing, if you can post a more accurate example i think we may be able to help more.
"Recursion is just a line of code"
-Karim Hosny-
My flickr

#4
qwerthex

qwerthex

    Newbie

  • Members
  • Pip
  • 2 posts
What patter are you attempting to display. You mention that simple numbers look better but what dictates how those numbers are used?