Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

03225186213 Group Title

how to make logic of recursion function?

  • one year ago
  • one year ago

  • This Question is Closed
  1. 03225186213 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    * ** *** ****

    • one year ago
  2. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    what do you mean? How does recursion work?

    • one year ago
  3. 03225186213 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    yes

    • one year ago
  4. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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 }

    • one year ago
  5. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    for recursion you would do public void a() int a = 0 while(a < 10) { a++ a(); }

    • one year ago
  6. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    which would call a again and again until you reached 9.

    • one year ago
  7. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    public void a() { int a = 0 while(a < 10) { a++ a(); } }

    • one year ago
  8. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    forgot my brackets BAD KZ :P

    • one year ago
  9. 03225186213 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    * ** *** **** print this using recurssion

    • one year ago
  10. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    you do know how to work strings right?

    • one year ago
  11. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • one year ago
  12. 03225186213 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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<<endl; spaces(a); }

    • one year ago
  13. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I personally would use an array, set each element to the # of * and then loop through the array.

    • one year ago
  14. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • one year ago
  15. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Like I said public void a() { //do something a(); }

    • one year ago
  16. 03225186213 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    whats the mistake?

    • one year ago
  17. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    you're calling 2 methods, you need to call 1 method that calls itself.

    • one year ago
  18. 03225186213 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i need to handle spaces as well as asteric

    • one year ago
  19. 03225186213 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    decrement in spaces and increment in asteric

    • one year ago
  20. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • one year ago
  21. rsmith6559 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    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.

    • one year ago
  22. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    plus you can read this link...seems a good one:) http://www.doc.ic.ac.uk/~wjk/C++Intro/RobMillerL8.html

    • one year ago
  23. KonradZuse Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ^exactly what I was saying :p.

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.