Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

shahzadjalbani

  • 2 years ago

Please define Recursion Function in C++.

  • This Question is Closed
  1. shahzadjalbani
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    @ash2326 @AwkwardsWhatIAmFor @ash__arya @ByteMe @bballer100 @bluesgut @Captain_Page_Turner @Chris2332 @comphw @DHASHNI @devendra_iiti

  2. DHASHNI
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 6

    recursion is when a function calls itself.That is, in the course of the function definition there is a call to that very same function. At first this may seem like a never ending loop, or like a dog chasing its tail. It can never catch it. So too it seems our function will never finish. This might be true is some cases, but in practice we can check to see if a certain condition is true and in that case exit (return from) our function. The case in which we end our recursion is called a base case . Additionally, just as in a loop, we must change some value and incrementally advance closer to our base case.

  3. DHASHNI
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 6

    http://www.danzig.us/cpp/recursion.html

  4. shahzadjalbani
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    @surdawi @SWAG @sue101

  5. Chris2332
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hi, how did you find the replies by DHASHNI?

  6. DHASHNI
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 6

    y so ...

  7. Chris2332
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    because he tagged another 3 people after the reply... which seems a bit weird!

  8. DHASHNI
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 6

    thats ok!!!!

  9. DHASHNI
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 6

    well if he's not satisfied with my idea ..... he should shift is'nt it!!!!

  10. shahzadjalbani
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    Explain further I understood little bit I need more explanation.... @DHASHNI @ash2326 @AwkwardsWhatIAmFor @ash__arya @hartnn @kropot72 @LonelyandForgotten

  11. DHASHNI
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 6

    #include <stdio.h> void recurse ( int count ) /* Each call gets its own copy of count */ { printf( "%d\n", count ); /* It is not necessary to increment count since each function's variables are separate (so each count will be initialized one greater) */ recurse ( count + 1 ); } int main() { recurse ( 1 ); /* First function call, so it starts at one */ return 0; } ====>>> This simple program will show the number of times the recurse function has been called by initializing each individual function call's count variable one greater than it was previous by passing in count + 1. Keep in mind that it is not a function call restarting itself; it is hundreds of function calls that are each unfinished. The best way to think of recursion is that each function call is a "process" being carried out by the computer. If we think of a program as being carried out by a group of people who can pass around information about the state of a task and instructions on performing the task, each recursive function call is a bit like each person asking the next person to follow the same set of instructions on some part of the task while the first person waits for the result. At some point, we're going to run out of people to carry out the instructions, just as our previous recursive functions ran out of space on the stack. There needs to be a way to avoid this! To halt a series of recursive calls, a recursive function will have a condition that controls when the function will finally stop calling itself. The condition where the function will not call itself is termed the base case of the function. Basically, it will usually be an if-statement that checks some variable for a condition (such as a number being less than zero, or greater than some other number) and if that condition is true, it will not allow the function to call itself again. (Or, it could check if a certain condition is true and only then allow the function to call itself)

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

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

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.