anonymous
  • anonymous
how to make logic of recursion function?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
* ** *** ****
KonradZuse
  • KonradZuse
what do you mean? How does recursion work?
anonymous
  • anonymous
yes

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

KonradZuse
  • KonradZuse
Okay so basically there is iteration and recursion. Recursion is basically calling a method or function within itself to get an answer. For example normally you would do an iteration like afor loop. for(int i = 0; i < size; i++) { //do something }
KonradZuse
  • KonradZuse
for recursion you would do public void a() int a = 0 while(a < 10) { a++ a(); }
KonradZuse
  • KonradZuse
which would call a again and again until you reached 9.
KonradZuse
  • KonradZuse
public void a() { int a = 0 while(a < 10) { a++ a(); } }
KonradZuse
  • KonradZuse
forgot my brackets BAD KZ :P
anonymous
  • anonymous
* ** *** **** print this using recurssion
KonradZuse
  • KonradZuse
you do know how to work strings right?
KonradZuse
  • KonradZuse
We aren't supposed to give out answers on here directly, but I am here to help if you need some guidance. I explained how recursion works, so let me know what you come up with :). There are many ways to complete this.
anonymous
  • anonymous
void main() { int a; cin>>a; spaces(a); } void spaces(int a) { cout<<" "; if(a<1) spaces(a-1); asteric(a); } void asteric(int a) { cout<<"*"; if(a>1) asteric(a-1); cout<
KonradZuse
  • KonradZuse
I personally would use an array, set each element to the # of * and then loop through the array.
KonradZuse
  • KonradZuse
woahs... You only need 1 method to do recursion. You're basically calling another 1 method from another, and then that method to the first one.
KonradZuse
  • KonradZuse
Like I said public void a() { //do something a(); }
anonymous
  • anonymous
whats the mistake?
KonradZuse
  • KonradZuse
you're calling 2 methods, you need to call 1 method that calls itself.
anonymous
  • anonymous
i need to handle spaces as well as asteric
anonymous
  • anonymous
decrement in spaces and increment in asteric
KonradZuse
  • KonradZuse
oic okay, so basically you will take the number total lets say 10. The 10th one would be the *, then on the next line 9 and 10 will be **, etc. Again you use only 1 method.
rsmith6559
  • rsmith6559
Recursion is usually used either for traversal or when a problem can be broken into smaller, identical problems and their solution can be combined into the final answer. In the case of traversals, this would be searching through a tree structure or graph or something similar. In the case of sub-problems, as you're proceeding through the sub-problems, you're basically breaking down the larger problem. Once you reach the "base case" ( where you want to stop recursing ), you start to "unwind" the recursion ( proceeding back up ) which would be the combining of the sub-problems into the answer to the original, large problem. Generally, the first block of a recursive function is the test for the base case. I'm not 100% sure of how you want to do your question, but if I'm given the length of the space/asterick string, I could decrement that length on the way down and keeping an original of the length (passing two variables), my base case being when that variable is 0. And on the unwind concatenate spaces up to original length minus this stack frame's length, padding it out with astericks and printing it. Or putting a linefeed on it and adding it to a (all of the strings) string and returning that up.
MicroBot
  • MicroBot
plus you can read this link...seems a good one:) http://www.doc.ic.ac.uk/~wjk/C++Intro/RobMillerL8.html
KonradZuse
  • KonradZuse
^exactly what I was saying :p.

Looking for something else?

Not the answer you are looking for? Search for more explanations.